Skip to content

Commit

Permalink
Add PHP 8.4 support to Smarty (#1084)
Browse files Browse the repository at this point in the history
* Add nullable types

* Removing deprecated E_STRICT constant from test suite.

* Added PHP 8.4 RC1 as test image

* PHP version bump in the README.md.

* Added PHP 8.4 to CI

* Add running tests for PHP 8.4
  • Loading branch information
jolelievre authored Nov 21, 2024
1 parent ffc4415 commit bf87aee
Show file tree
Hide file tree
Showing 38 changed files with 123 additions and 103 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

compiler:
- default
Expand All @@ -50,6 +51,9 @@ jobs:
- os: ubuntu-latest
php-version: "8.3"
compiler: jit
- os: ubuntu-latest
php-version: "8.4"
compiler: jit
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

## Requirements
Smarty can be run with PHP 7.1 to PHP 8.3.
Smarty can be run with PHP 7.1 to PHP 8.4.

## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
Expand Down
6 changes: 3 additions & 3 deletions demo/plugins/resource.extendsall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$uid = '';
$sources = array();
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ services:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php83/Dockerfile
dockerfile: ./utilities/testrunners/php83/Dockerfile
php84:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php84/Dockerfile
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Getting started

## Requirements
Smarty can be run with PHP 7.1 to PHP 8.3.
Smarty can be run with PHP 7.1 to PHP 8.4.

## Installation
Smarty can be installed with [Composer](https://getcomposer.org/).
Expand Down
12 changes: 6 additions & 6 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,11 @@ public function loadPlugin($plugin_name, $check = true)
/**
* Get unique template id
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty_Internal_Template $template
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty_Internal_Template|null $template
*
* @return string
* @throws \SmartyException
Expand All @@ -1050,7 +1050,7 @@ public function _getTemplateId(
$cache_id = null,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null
?Smarty_Internal_Template $template = null
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
Expand Down
8 changes: 4 additions & 4 deletions libs/sysplugins/smarty_cacheresource.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ abstract public function populateTimestamp(Smarty_Template_Cached $cached);
/**
* Read the cached template and process header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(
Smarty_Internal_Template $_template,
Smarty_Template_Cached $cached = null,
?Smarty_Template_Cached $cached = null,
$update = false
);

Expand Down
8 changes: 4 additions & 4 deletions libs/sysplugins/smarty_cacheresource_custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
/**
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
?Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
Expand Down
8 changes: 4 additions & 4 deletions libs/sysplugins/smarty_cacheresource_keyvaluestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
/**
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
?Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
Expand Down
8 changes: 4 additions & 4 deletions libs/sysplugins/smarty_internal_cacheresource_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public function populateTimestamp(Smarty_Template_Cached $cached)
/**
* Read the cached template and process its header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
?Smarty_Template_Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function assignByRef($tpl_var, &$value, $nocache = false)
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
public function getTemplateVars($varName = null, ?Smarty_Internal_Data $_ptr = null, $searchParents = true)
{
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
}
Expand All @@ -200,7 +200,7 @@ public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = nu
*
* @param \Smarty_Internal_Data|null $data
*/
public function _mergeVars(Smarty_Internal_Data $data = null)
public function _mergeVars(?Smarty_Internal_Data $data = null)
{
if (isset($data)) {
if (!empty($this->tpl_vars)) {
Expand Down
10 changes: 5 additions & 5 deletions libs/sysplugins/smarty_internal_method_createdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Smarty_Internal_Method_CreateData
* @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty
* variables
* @param string $name optional data block name
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty|null $parent next higher level of Smarty
* variables
* @param string $name optional data block name
*
* @return \Smarty_Data data object
*/
public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null)
public function createData(Smarty_Internal_TemplateBase $obj, ?Smarty_Internal_Data $parent = null, $name = null)
{
/* @var Smarty $smarty */
$smarty = $obj->_getSmartyObj();
Expand Down
12 changes: 6 additions & 6 deletions libs/sysplugins/smarty_internal_method_gettemplatevars.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class Smarty_Internal_Method_GetTemplateVars
* @api Smarty::getTemplateVars()
* @link https://www.smarty.net/docs/en/api.get.template.vars.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty|null $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars(
Smarty_Internal_Data $data,
$varName = null,
Smarty_Internal_Data $_ptr = null,
?Smarty_Internal_Data $_ptr = null,
$searchParents = true
) {
if (isset($varName)) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public function getTemplateVars(
public function _getVariable(
Smarty_Internal_Data $data,
$varName,
Smarty_Internal_Data $_ptr = null,
?Smarty_Internal_Data $_ptr = null,
$searchParents = true,
$errorEnable = true
) {
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_resource_eval.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name);
$source->timestamp = $source->exists = true;
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_resource_extends.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @throws SmartyException
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$uid = '';
$sources = array();
Expand Down
8 changes: 4 additions & 4 deletions libs/sysplugins/smarty_internal_resource_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @throws \SmartyException
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
Expand Down Expand Up @@ -93,12 +93,12 @@ public function getBasename(Smarty_Template_Source $source)
* build template filepath by traversing the template_dir array
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @return string fully qualified filepath
* @throws SmartyException
*/
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
protected function buildFilepath(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$file = $source->name;
// absolute file ?
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_resource_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
if (strpos($source->resource, '://') !== false) {
$source->filepath = $source->resource;
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_resource_string.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Internal_Template|null $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
$source->timestamp = $source->exists = true;
Expand Down
12 changes: 6 additions & 6 deletions libs/sysplugins/smarty_internal_runtime_codeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Smarty_Internal_Runtime_CodeFrame
/**
* Create code frame for compiled and cached templates
*
* @param Smarty_Internal_Template $_template
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param Smarty_Internal_Template $_template
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty_Internal_TemplateCompilerBase|null $compiler
*
* @return string
*/
Expand All @@ -30,7 +30,7 @@ public function create(
$content = '',
$functions = '',
$cache = false,
Smarty_Internal_TemplateCompilerBase $compiler = null
?Smarty_Internal_TemplateCompilerBase $compiler = null
) {
// build property code
$properties[ 'version' ] = Smarty::SMARTY_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_runtime_inheritance.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name,
public function process(
Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
Smarty_Internal_Block $parent = null
?Smarty_Internal_Block $parent = null
) {
if ($block->hide && !isset($block->child)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function __construct(
$template_resource,
Smarty $smarty,
Smarty_Internal_Data $_parent = null,
?Smarty_Internal_Data $_parent = null,
$_cache_id = null,
$_compile_id = null,
$_caching = null,
Expand Down
10 changes: 5 additions & 5 deletions libs/sysplugins/smarty_internal_templatecompilerbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function __construct(Smarty $smarty)
public function compileTemplate(
Smarty_Internal_Template $template,
$nocache = null,
Smarty_Internal_TemplateCompilerBase $parent_compiler = null
?Smarty_Internal_TemplateCompilerBase $parent_compiler = null
) {
// get code frame of compiled template
$_compiled_code = $template->smarty->ext->_codeFrame->create(
Expand All @@ -407,17 +407,17 @@ public function compileTemplate(
/**
* Compile template source and run optional post filter
*
* @param \Smarty_Internal_Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty_Internal_TemplateCompilerBase $parent_compiler
* @param \Smarty_Internal_Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty_Internal_TemplateCompilerBase|null $parent_compiler
*
* @return string
* @throws \Exception
*/
public function compileTemplateSource(
Smarty_Internal_Template $template,
$nocache = null,
Smarty_Internal_TemplateCompilerBase $parent_compiler = null
?Smarty_Internal_TemplateCompilerBase $parent_compiler = null
) {
try {
// save template object in compiler class
Expand Down
Loading

0 comments on commit bf87aee

Please sign in to comment.