Prevent deprecation notices for implode, json_encode and substr modifiers.

This commit is contained in:
Simon Wisselink
2024-02-26 12:18:48 +01:00
parent 6e067ed327
commit 5936795bef
4 changed files with 41 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Using the `|implode`, `|json_encode` and `|substr` modifiers does not generate a deprecation warning anymore as they will continue to be supported in v5 [#939](https://github.com/smarty-php/smarty/issues/939)
## [4.3.4] - 2023-09-14 ## [4.3.4] - 2023-09-14
## [4.3.3] - 2023-09-14 ## [4.3.3] - 2023-09-14

View File

@@ -0,0 +1,15 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
function smarty_modifier_implode($values, $separator = '')
{
if (is_array($separator)) {
return implode((string) ($values ?? ''), (array) $separator);
}
return implode((string) ($separator ?? ''), (array) $values);
}

View File

@@ -0,0 +1,11 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
function smarty_modifiercompiler_json_encode($params) {
return 'json_encode(' . $params[0] . (isset($params[1]) ? ', (int) ' . $params[1] : '') . ')';
}

View File

@@ -0,0 +1,12 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
function smarty_modifiercompiler_substr($params) {
return 'substr((string) ' . $params[0] . ', (int) ' . $params[1] .
(isset($params[2]) ? ', (int) ' . $params[2] : '') . ')';
}