Add PHP 8.4 support to Smarty (#1043)

This commit is contained in:
Wim Wisselink
2024-11-20 15:59:26 +01:00
committed by GitHub
parent a1b4c9c551
commit 1b06b37db2
30 changed files with 51 additions and 31 deletions

View File

@ -33,6 +33,7 @@ jobs:
- "8.1" - "8.1"
- "8.2" - "8.2"
- "8.3" - "8.3"
- "8.4"
compiler: compiler:
- default - default
@ -50,6 +51,9 @@ jobs:
- os: ubuntu-latest - os: ubuntu-latest
php-version: "8.3" php-version: "8.3"
compiler: jit compiler: jit
- os: ubuntu-latest
php-version: "8.4"
compiler: jit
steps: steps:
- name: Checkout - name: Checkout

View File

@ -7,7 +7,7 @@ Smarty is a template engine for PHP, facilitating the separation of presentation
Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it. Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it.
## Requirements ## Requirements
Smarty v5 can be run with PHP 7.2 to PHP 8.3. Smarty v5 can be run with PHP 7.2 to PHP 8.4.
## Installation ## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/). Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).

View File

@ -42,6 +42,11 @@ services:
service: base service: base
build: build:
dockerfile: ./utilities/testrunners/php83/Dockerfile dockerfile: ./utilities/testrunners/php83/Dockerfile
php84:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php84/Dockerfile
volumes: volumes:
smarty-code: smarty-code:

View File

@ -14,3 +14,4 @@ $COMPOSE_CMD run --rm php80 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php81 ./run-tests.sh $@ && \ $COMPOSE_CMD run --rm php81 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php82 ./run-tests.sh $@ $COMPOSE_CMD run --rm php82 ./run-tests.sh $@
$COMPOSE_CMD run --rm php83 ./run-tests.sh $@ $COMPOSE_CMD run --rm php83 ./run-tests.sh $@
$COMPOSE_CMD run --rm php84 ./run-tests.sh $@

View File

@ -44,7 +44,7 @@ abstract class Base
*/ */
abstract public function process( abstract public function process(
Template $_template, Template $_template,
Cached $cached = null, ?Cached $cached = null,
$update = false $update = false
); );

View File

@ -139,7 +139,7 @@ abstract class Custom extends Base
*/ */
public function process( public function process(
Template $_smarty_tpl, Template $_smarty_tpl,
\Smarty\Template\Cached $cached = null, ?\Smarty\Template\Cached $cached = null,
$update = false $update = false
) { ) {
if (!$cached) { if (!$cached) {

View File

@ -99,7 +99,7 @@ class File extends Base
*/ */
public function process( public function process(
Template $_smarty_tpl, Template $_smarty_tpl,
Cached $cached = null, ?Cached $cached = null,
$update = false $update = false
) { ) {
$_smarty_tpl->getCached()->setValid(false); $_smarty_tpl->getCached()->setValid(false);

View File

@ -103,7 +103,7 @@ abstract class KeyValueStore extends Base
*/ */
public function process( public function process(
Template $_smarty_tpl, Template $_smarty_tpl,
Cached $cached = null, ?Cached $cached = null,
$update = false $update = false
) { ) {
if (!$cached) { if (!$cached) {

View File

@ -41,7 +41,7 @@ class CodeFrame
$content = '', $content = '',
$functions = '', $functions = '',
$cache = false, $cache = false,
\Smarty\Compiler\Template $compiler = null ?\Smarty\Compiler\Template $compiler = null
) { ) {
// build property code // build property code
$properties[ 'version' ] = \Smarty\Smarty::SMARTY_VERSION; $properties[ 'version' ] = \Smarty\Smarty::SMARTY_VERSION;

View File

@ -374,7 +374,7 @@ class Template extends BaseCompiler {
* @throws CompilerException * @throws CompilerException
* @throws Exception * @throws Exception
*/ */
public function compileTemplateSource(\Smarty\Template $template, \Smarty\Compiler\Template $parent_compiler = null) { public function compileTemplateSource(\Smarty\Template $template, ?\Smarty\Compiler\Template $parent_compiler = null) {
try { try {
// save template object in compiler class // save template object in compiler class
$this->template = $template; $this->template = $template;

View File

@ -16,14 +16,14 @@ class CompilerException extends Exception {
* @param int $code The Exception code. * @param int $code The Exception code.
* @param string|null $filename The filename where the exception is thrown. * @param string|null $filename The filename where the exception is thrown.
* @param int|null $line The line number where the exception is thrown. * @param int|null $line The line number where the exception is thrown.
* @param Throwable|null $previous The previous exception used for the exception chaining. * @param \Throwable|null $previous The previous exception used for the exception chaining.
*/ */
public function __construct( public function __construct(
string $message = "", string $message = "",
int $code = 0, int $code = 0,
?string $filename = null, ?string $filename = null,
?int $line = null, ?int $line = null,
Throwable $previous = null ?\Throwable $previous = null
) { ) {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);

View File

@ -112,7 +112,7 @@ abstract class BasePlugin
* @param Source $source source object * @param Source $source source object
* @param Template|null $_template template object * @param Template|null $_template template object
*/ */
abstract public function populate(Source $source, \Smarty\Template $_template = null); abstract public function populate(Source $source, ?\Smarty\Template $_template = null);
/** /**
* populate Source Object with timestamp and exists from Resource * populate Source Object with timestamp and exists from Resource

View File

@ -50,7 +50,7 @@ abstract class CustomPlugin extends BasePlugin {
* @param Source $source source object * @param Source $source source object
* @param Template|null $_template template object * @param Template|null $_template template object
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, ?Template $_template = null) {
$source->uid = sha1($source->type . ':' . $source->name); $source->uid = sha1($source->type . ':' . $source->name);
$mtime = $this->fetchTimestamp($source->name); $mtime = $this->fetchTimestamp($source->name);
if ($mtime !== null) { if ($mtime !== null) {

View File

@ -23,7 +23,7 @@ class ExtendsPlugin extends BasePlugin
* *
* @throws Exception * @throws Exception
*/ */
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$uid = ''; $uid = '';
$sources = array(); $sources = array();

View File

@ -32,7 +32,7 @@ class FilePlugin extends BasePlugin {
* *
* @throws Exception * @throws Exception
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, ?Template $_template = null) {
$source->uid = sha1( $source->uid = sha1(
$source->name . ($source->isConfig ? $source->getSmarty()->_joined_config_dir : $source->name . ($source->isConfig ? $source->getSmarty()->_joined_config_dir :

View File

@ -33,7 +33,7 @@ class StreamPlugin extends RecompiledPlugin {
* *
* @return void * @return void
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, ?Template $_template = null) {
$source->uid = false; $source->uid = false;
$source->content = $this->getContent($source); $source->content = $this->getContent($source);
$source->timestamp = $source->exists = !!$source->content; $source->timestamp = $source->exists = !!$source->content;

View File

@ -31,7 +31,7 @@ class StringPlugin extends BasePlugin {
* *
* @return void * @return void
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, ?Template $_template = null) {
$source->uid = sha1($source->name); $source->uid = sha1($source->name);
$source->timestamp = $source->exists = true; $source->timestamp = $source->exists = true;
} }

View File

@ -162,7 +162,7 @@ class InheritanceRuntime {
private function processBlock( private function processBlock(
Template $tpl, Template $tpl,
\Smarty\Runtime\Block $block, \Smarty\Runtime\Block $block,
\Smarty\Runtime\Block $parent = null ?\Smarty\Runtime\Block $parent = null
) { ) {
if ($block->hide && !isset($block->child)) { if ($block->hide && !isset($block->child)) {
return; return;

View File

@ -115,7 +115,7 @@ class Template extends TemplateBase {
public function __construct( public function __construct(
$template_resource, $template_resource,
Smarty $smarty, Smarty $smarty,
\Smarty\Data $_parent = null, ?\Smarty\Data $_parent = null,
$_cache_id = null, $_cache_id = null,
$_compile_id = null, $_compile_id = null,
$_caching = null, $_caching = null,
@ -248,7 +248,7 @@ class Template extends TemplateBase {
$caching, $caching,
$cache_lifetime, $cache_lifetime,
array $extra_vars = [], array $extra_vars = [],
int $scope = null, ?int $scope = null,
?string $currentDir = null ?string $currentDir = null
) { ) {
@ -462,7 +462,7 @@ class Template extends TemplateBase {
* @return string * @return string
* @throws Exception * @throws Exception
*/ */
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) { public function createCodeFrame($content = '', $functions = '', $cache = false, ?\Smarty\Compiler\Template $compiler = null) {
return $this->getCodeFrameCompiler()->create($content, $functions, $cache, $compiler); return $this->getCodeFrameCompiler()->create($content, $functions, $cache, $compiler);
} }

View File

@ -134,9 +134,9 @@ class Source {
* @throws Exception * @throws Exception
*/ */
public static function load( public static function load(
Template $_template = null, ?Template $_template = null,
Smarty $smarty = null, ?Smarty $smarty = null,
$template_resource = null $template_resource = null
) { ) {
if ($_template) { if ($_template) {
$smarty = $_template->getSmarty(); $smarty = $_template->getSmarty();

View File

@ -179,7 +179,7 @@ abstract class TemplateBase extends Data {
* @api Smarty::createData() * @api Smarty::createData()
* *
*/ */
public function createData(Data $parent = null, $name = null) { public function createData(?Data $parent = null, $name = null) {
/* @var Smarty $smarty */ /* @var Smarty $smarty */
$smarty = $this->getSmarty(); $smarty = $this->getSmarty();
$dataObj = new Data($parent, $smarty, $name); $dataObj = new Data($parent, $smarty, $name);

View File

@ -64,7 +64,7 @@ class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
*/ */
public static function setUpBeforeClass(): void public static function setUpBeforeClass(): void
{ {
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_USER_DEPRECATED); error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
self::$init = true; self::$init = true;
self::$pluginsdir =self::getSmartyPluginsDir(); self::$pluginsdir =self::getSmartyPluginsDir();
} }

View File

@ -12,7 +12,7 @@ class Smarty_Resource_FiletestPlugin extends FilePlugin
* @param Source $source source object * @param Source $source source object
* @param Template $_template template object * @param Template $_template template object
*/ */
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
parent::populate($source, $_template); parent::populate($source, $_template);
if ($source->exists) { if ($source->exists) {

View File

@ -34,7 +34,7 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin
* @param Source $source source object * @param Source $source source object
* @param Template $_template template object * @param Template $_template template object
*/ */
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$segment = ''; $segment = '';
if ($this->segment) { if ($this->segment) {

View File

@ -16,7 +16,7 @@ use Smarty\Template\Source;
class Smarty_Resource_Db extends RecompiledPlugin { class Smarty_Resource_Db extends RecompiledPlugin {
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, ?Template $_template = null) {
$source->uid = sha1($source->resource); $source->uid = sha1($source->resource);
$source->timestamp = 1000000000; $source->timestamp = 1000000000;
$source->exists = true; $source->exists = true;

View File

@ -16,7 +16,7 @@ use Smarty\Template\Source;
class Smarty_Resource_Db2 extends RecompiledPlugin class Smarty_Resource_Db2 extends RecompiledPlugin
{ {
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$source->uid = sha1($source->resource); $source->uid = sha1($source->resource);
$source->timestamp = 0; $source->timestamp = 0;

View File

@ -15,7 +15,7 @@ use Smarty\Template\Source;
class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
{ {
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$source->uid = sha1($source->resource); $source->uid = sha1($source->resource);
$source->timestamp = 0; $source->timestamp = 0;

View File

@ -16,7 +16,7 @@ use Smarty\Template\Source;
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
{ {
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$source->uid = sha1($source->resource); $source->uid = sha1($source->resource);
$source->timestamp = 0; $source->timestamp = 0;

View File

@ -22,7 +22,7 @@ class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
* *
* @return void * @return void
*/ */
public function populate(Source $source, Template $_template = null) public function populate(Source $source, ?Template $_template = null)
{ {
$uid = ''; $uid = '';
$sources = array(); $sources = array();

View File

@ -0,0 +1,10 @@
FROM php:8.4-rc-cli-bullseye
## Basic utilities
RUN apt-get update -yqq && apt-get install -y curl apt-utils git zip unzip
## Composer
COPY ./utilities/testrunners/shared/install-composer.sh /root/install-composer.sh
WORKDIR /root
RUN sh ./install-composer.sh
RUN mv ./composer.phar /usr/local/bin/composer