|
| 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 | + |
0 commit comments