Skip to content

Commit 88ba83e

Browse files
committed
smarty/4-PHP8-compatible-code-fixes
1 parent 527293c commit 88ba83e

File tree

51 files changed

+321
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+321
-0
lines changed

add_attributes.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Batch script to add #[\AllowDynamicProperties] attribute to classes
4+
*/
5+
6+
$classesToUpdate = [
7+
// Cache resources
8+
'libs/sysplugins/smarty_cacheresource.php' => 'abstract class Smarty_CacheResource',
9+
'libs/sysplugins/smarty_cacheresource_custom.php' => 'abstract class Smarty_CacheResource_Custom',
10+
'libs/sysplugins/smarty_cacheresource_keyvaluestore.php' => 'abstract class Smarty_CacheResource_KeyValueStore',
11+
'libs/sysplugins/smarty_internal_cacheresource_file.php' => 'class Smarty_Internal_CacheResource_File',
12+
13+
// Parsers and Lexers
14+
'libs/sysplugins/smarty_internal_templateparser.php' => 'class Smarty_Internal_Templateparser',
15+
'libs/sysplugins/smarty_internal_templatelexer.php' => 'class Smarty_Internal_Templatelexer',
16+
'libs/sysplugins/smarty_internal_configfileparser.php' => 'class Smarty_Internal_Configfileparser',
17+
'libs/sysplugins/smarty_internal_configfilelexer.php' => 'class Smarty_Internal_Configfilelexer',
18+
19+
// Compile base
20+
'libs/sysplugins/smarty_internal_compilebase.php' => 'abstract class Smarty_Internal_CompileBase',
21+
22+
// Config compiler
23+
'libs/sysplugins/smarty_internal_config_file_compiler.php' => 'class Smarty_Internal_Config_File_Compiler',
24+
25+
// Smart compiler
26+
'libs/sysplugins/smarty_internal_smartytemplatecompiler.php' => 'class Smarty_Internal_SmartyTemplateCompiler',
27+
28+
// Debug
29+
'libs/sysplugins/smarty_internal_debug.php' => 'class Smarty_Internal_Debug',
30+
31+
// ParseTree classes
32+
'libs/sysplugins/smarty_internal_parsetree.php' => 'abstract class Smarty_Internal_ParseTree',
33+
];
34+
35+
$basePath = __DIR__;
36+
$comment = '// PHP 8.2+: Allow dynamic properties for internal state and extensibility';
37+
38+
foreach ($classesToUpdate as $file => $classDeclaration) {
39+
$filePath = $basePath . '/' . $file;
40+
41+
if (!file_exists($filePath)) {
42+
echo "SKIP: $file (not found)\n";
43+
continue;
44+
}
45+
46+
$content = file_get_contents($filePath);
47+
48+
// Check if already has attribute
49+
if (strpos($content, '#[\AllowDynamicProperties]') !== false) {
50+
echo "SKIP: $file (already has attribute)\n";
51+
continue;
52+
}
53+
54+
// Add attribute before class declaration
55+
$pattern = '/(\n)(' . preg_quote($classDeclaration, '/') . ')/';
56+
$replacement = "\n$comment\n#[\\AllowDynamicProperties]\n$2";
57+
58+
$newContent = preg_replace($pattern, $replacement, $content, 1, $count);
59+
60+
if ($count > 0) {
61+
file_put_contents($filePath, $newContent);
62+
echo "✓ Updated: $file\n";
63+
} else {
64+
echo "FAIL: $file (pattern not found)\n";
65+
}
66+
}
67+
68+
echo "\nDone!\n";
69+

add_attributes2.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Batch script part 2 - Runtime, methods, and more resource classes
4+
*/
5+
6+
$classesToUpdate = [
7+
// All Runtime classes
8+
'libs/sysplugins/smarty_internal_runtime_cachemodify.php' => 'class Smarty_Internal_Runtime_CacheModify',
9+
'libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php' => 'class Smarty_Internal_Runtime_CacheResourceFile',
10+
'libs/sysplugins/smarty_internal_runtime_capture.php' => 'class Smarty_Internal_Runtime_Capture',
11+
'libs/sysplugins/smarty_internal_runtime_codeframe.php' => 'class Smarty_Internal_Runtime_CodeFrame',
12+
'libs/sysplugins/smarty_internal_runtime_filterhandler.php' => 'class Smarty_Internal_Runtime_FilterHandler',
13+
'libs/sysplugins/smarty_internal_runtime_foreach.php' => 'class Smarty_Internal_Runtime_Foreach',
14+
'libs/sysplugins/smarty_internal_runtime_getincludepath.php' => 'class Smarty_Internal_Runtime_GetIncludePath',
15+
'libs/sysplugins/smarty_internal_runtime_inheritance.php' => 'class Smarty_Internal_Runtime_Inheritance',
16+
'libs/sysplugins/smarty_internal_runtime_tplfunction.php' => 'class Smarty_Internal_Runtime_TplFunction',
17+
'libs/sysplugins/smarty_internal_runtime_updatecache.php' => 'class Smarty_Internal_Runtime_UpdateCache',
18+
'libs/sysplugins/smarty_internal_runtime_updatescope.php' => 'class Smarty_Internal_Runtime_UpdateScope',
19+
'libs/sysplugins/smarty_internal_runtime_writefile.php' => 'class Smarty_Internal_Runtime_WriteFile',
20+
21+
// Additional Resource implementations
22+
'libs/sysplugins/smarty_internal_resource_file.php' => 'class Smarty_Internal_Resource_File',
23+
'libs/sysplugins/smarty_internal_resource_string.php' => 'class Smarty_Internal_Resource_String',
24+
'libs/sysplugins/smarty_internal_resource_eval.php' => 'class Smarty_Internal_Resource_Eval',
25+
'libs/sysplugins/smarty_internal_resource_extends.php' => 'class Smarty_Internal_Resource_Extends',
26+
'libs/sysplugins/smarty_internal_resource_php.php' => 'class Smarty_Internal_Resource_Php',
27+
'libs/sysplugins/smarty_internal_resource_stream.php' => 'class Smarty_Internal_Resource_Stream',
28+
'libs/sysplugins/smarty_resource_custom.php' => 'abstract class Smarty_Resource_Custom',
29+
'libs/sysplugins/smarty_resource_uncompiled.php' => 'abstract class Smarty_Resource_Uncompiled',
30+
'libs/sysplugins/smarty_resource_recompiled.php' => 'abstract class Smarty_Resource_Recompiled',
31+
32+
// Template config
33+
'libs/sysplugins/smarty_template_config.php' => 'class Smarty_Template_Config',
34+
35+
// Exception classes
36+
'libs/sysplugins/smartyexception.php' => 'class SmartyException',
37+
'libs/sysplugins/smartycompilerexception.php' => 'class SmartyCompilerException',
38+
39+
// Undefined and test classes
40+
'libs/sysplugins/smarty_internal_undefined.php' => 'class Smarty_Internal_Undefined',
41+
'libs/sysplugins/smarty_undefined_variable.php' => 'class Smarty_Undefined_Variable',
42+
'libs/sysplugins/smarty_internal_testinstall.php' => 'class Smarty_Internal_TestInstall',
43+
44+
// Nocache insert
45+
'libs/sysplugins/smarty_internal_nocache_insert.php' => 'class Smarty_Internal_Nocache_Insert',
46+
];
47+
48+
$basePath = __DIR__;
49+
$comment = '// PHP 8.2+: Allow dynamic properties for internal state and extensibility';
50+
51+
$updated = 0;
52+
$skipped = 0;
53+
$failed = 0;
54+
55+
foreach ($classesToUpdate as $file => $classDeclaration) {
56+
$filePath = $basePath . '/' . $file;
57+
58+
if (!file_exists($filePath)) {
59+
echo "SKIP: $file (not found)\n";
60+
$skipped++;
61+
continue;
62+
}
63+
64+
$content = file_get_contents($filePath);
65+
66+
// Check if already has attribute
67+
if (strpos($content, '#[\AllowDynamicProperties]') !== false) {
68+
echo "SKIP: $file (already has attribute)\n";
69+
$skipped++;
70+
continue;
71+
}
72+
73+
// Add attribute before class declaration
74+
$pattern = '/(\n)(' . preg_quote($classDeclaration, '/') . ')/';
75+
$replacement = "\n$comment\n#[\\AllowDynamicProperties]\n$2";
76+
77+
$newContent = preg_replace($pattern, $replacement, $content, 1, $count);
78+
79+
if ($count > 0) {
80+
file_put_contents($filePath, $newContent);
81+
echo "✓ Updated: $file\n";
82+
$updated++;
83+
} else {
84+
echo "FAIL: $file (pattern not found)\n";
85+
$failed++;
86+
}
87+
}
88+
89+
echo "\n================\n";
90+
echo "Updated: $updated\n";
91+
echo "Skipped: $skipped\n";
92+
echo "Failed: $failed\n";
93+
echo "================\n";
94+

add_attributes3.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Batch script part 3 - All compile classes
4+
*/
5+
6+
// Get all compile class files
7+
$files = glob(__DIR__ . '/libs/sysplugins/smarty_internal_compile_*.php');
8+
9+
$basePath = __DIR__;
10+
$comment = '// PHP 8.2+: Allow dynamic properties for compiler state and tag-specific data';
11+
12+
$updated = 0;
13+
$skipped = 0;
14+
$failed = 0;
15+
16+
foreach ($files as $filePath) {
17+
$content = file_get_contents($filePath);
18+
19+
// Check if already has attribute
20+
if (strpos($content, '#[\AllowDynamicProperties]') !== false) {
21+
$skipped++;
22+
continue;
23+
}
24+
25+
// Find all class declarations in the file
26+
preg_match_all('/^(abstract )?class (Smarty_Internal_Compile_\w+)/m', $content, $matches, PREG_SET_ORDER);
27+
28+
if (empty($matches)) {
29+
continue;
30+
}
31+
32+
$modified = false;
33+
foreach ($matches as $match) {
34+
$classDeclaration = trim($match[0]);
35+
36+
// Add attribute before class declaration
37+
$pattern = '/(\n)(' . preg_quote($classDeclaration, '/') . ')/';
38+
$replacement = "\n$comment\n#[\\AllowDynamicProperties]\n$2";
39+
40+
$newContent = preg_replace($pattern, $replacement, $content, 1, $count);
41+
42+
if ($count > 0) {
43+
$content = $newContent;
44+
$modified = true;
45+
}
46+
}
47+
48+
if ($modified) {
49+
file_put_contents($filePath, $content);
50+
echo "✓ Updated: " . basename($filePath) . "\n";
51+
$updated++;
52+
} else {
53+
$failed++;
54+
}
55+
}
56+
57+
echo "\n================\n";
58+
echo "Updated: $updated\n";
59+
echo "Skipped: $skipped\n";
60+
echo "Failed: $failed\n";
61+
echo "================\n";
62+

libs/Smarty.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
* @method int compileAllConfig(string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, $max_errors = null)
103103
* @method int clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
104104
*/
105+
// PHP 8.2+: Allow dynamic properties for user extensibility and configuration
106+
#[\AllowDynamicProperties]
105107
class Smarty extends Smarty_Internal_TemplateBase
106108
{
107109
/**

libs/sysplugins/smarty_cacheresource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @subpackage Cacher
1414
* @author Rodney Rehm
1515
*/
16+
// PHP 8.2+: Allow dynamic properties for internal state and extensibility
17+
#[\AllowDynamicProperties]
1618
abstract class Smarty_CacheResource
1719
{
1820
/**

libs/sysplugins/smarty_cacheresource_custom.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @subpackage Cacher
1414
* @author Rodney Rehm
1515
*/
16+
// PHP 8.2+: Allow dynamic properties for internal state and extensibility
17+
#[\AllowDynamicProperties]
1618
abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
1719
{
1820
/**

libs/sysplugins/smarty_cacheresource_keyvaluestore.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* @subpackage Cacher
2929
* @author Rodney Rehm
3030
*/
31+
// PHP 8.2+: Allow dynamic properties for internal state and extensibility
32+
#[\AllowDynamicProperties]
3133
abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
3234
{
3335
/**

libs/sysplugins/smarty_data.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @package Smarty
1616
* @subpackage Template
1717
*/
18+
// PHP 8.2+: Allow dynamic properties for data object flexibility (inherits from Smarty_Internal_Data)
19+
#[\AllowDynamicProperties]
1820
class Smarty_Data extends Smarty_Internal_Data
1921
{
2022
/**

libs/sysplugins/smarty_internal_cacheresource_file.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @package Smarty
1616
* @subpackage Cacher
1717
*/
18+
// PHP 8.2+: Allow dynamic properties for internal state and extensibility
19+
#[\AllowDynamicProperties]
1820
class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
1921
{
2022
/**

libs/sysplugins/smarty_internal_compilebase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @package Smarty
1414
* @subpackage Compiler
1515
*/
16+
// PHP 8.2+: Allow dynamic properties for internal state and extensibility
17+
#[\AllowDynamicProperties]
1618
abstract class Smarty_Internal_CompileBase
1719
{
1820
/**

0 commit comments

Comments
 (0)