Files
smarty/tests/PHPUnit_Smarty.php

638 lines
20 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* This file is part of the Smarty PHPUnit tests.
*
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
use Smarty\Exception;
use Smarty\TemplateBase;
use Smarty\Template;
/**
* Smarty Test Case Fixture
*/
class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
{
/**
* Smarty object
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @var \Smarty\Smarty
*/
public $smarty = null;
/**
* Flag for initialization at first test
*
* @var bool
*/
public static $init = true;
/**
* Count test number
*
* @var bool
*/
public static $testNumber = 0;
/**
* Configuration data from config.xml
*
* @var array
*/
public static $config = null;
/**
* Saved current working directory
*
* @var null
*/
public static $cwd = null;
/**
* PDO object for Mysql tests
*
* @var PDO
*/
public static $pdo = null;
public static $pluginsdir = null;
/**
* This method is called before the first test of this test class is run.
*
*/
public static function setUpBeforeClass(): void
{
2024-11-20 15:59:26 +01:00
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
self::$init = true;
self::$pluginsdir =self::getSmartyPluginsDir();
}
/**
* This method is called after the last test of this test class is run.
*
*/
public static function tearDownAfterClass(): void
{
//self::$pdo = null;
self::$testNumber = 0;
}
/**
* Constructs a test case with the given name.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = array(), $dataName = '')
{
date_default_timezone_set('Europe/Berlin');
if (!defined('individualFolders')) {
define('individualFolders', true);
}
parent::__construct($name, $data, $dataName);
}
/**
* Setup Smarty instance called for each test
*
* @param null $dir working directory
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function setUpSmarty($dir)
{
static $s_dir;
// set up current working directory
chdir($dir);
self::$cwd = getcwd();
// create missing folders for test
if (self::$init) {
if (!is_dir($dir . '/templates')) {
mkdir($dir . '/templates');
}
if (!is_dir($dir . '/configs')) {
mkdir($dir . '/configs');
}
if (individualFolders != 'true') {
if (!isset($s_dir[ $dir ])) {
$this->cleanDir($dir . '/templates_c');
$this->cleanDir($dir . '/cache');
if (is_dir($dir . '/templates_tmp')) {
$this->cleanDir($dir . '/templates_tmp');
}
$s_dir[ $dir ] = true;
}
$dir = __DIR__;
}
if (!is_dir($dir . '/templates_c')) {
mkdir($dir . '/templates_c');
}
chmod($dir . '/templates_c', 0775);
if (!is_dir($dir . '/cache')) {
mkdir($dir . '/cache');
chmod($dir . '/cache', 0775);
}
self::$init = false;
}
clearstatcache();
// instance Smarty class
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$this->smarty = new \Smarty\Smarty();
if (individualFolders != 'true') {
$this->smarty->setCompileDir(__DIR__ . '/templates_c');
$this->smarty->setCacheDir(__DIR__ . '/cache');
}
}
/**
* Create Mysql PDO object
*
*/
final public function getConnection()
{
if (PHPUnit_Smarty::$pdo == null) {
try {
PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD);
}
catch (PDOException $e) {
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
throw new Exception('Mysql Resource failed: ' . $e->getMessage());
}
$timezone = date_default_timezone_get();
$j = PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';");
}
}
/**
* Create table for Mysql resource
*
*/
public function initMysqlResource()
{
$this->getConnection();
PHPUnit_Smarty::$pdo->exec("DROP TABLE `templates`");
PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `templates` (
`name` varchar(100) NOT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`source` text,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Create table for Mysql cache resource
*
*/
public function initMysqlCache()
{
$this->getConnection();
PHPUnit_Smarty::$pdo->exec("DROP TABLE `output_cache`");
PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
`name` varchar(256) NOT NULL,
`id` char(40) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`content` mediumblob NOT NULL,
PRIMARY KEY (`id`),
KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
// PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
//`id` char(40) NOT NULL,
//`name` varchar(250) NOT NULL,
//`cache_id` varchar(250) DEFAULT NULL,
//`compile_id` varchar(250) DEFAULT NULL,
//`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
//`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
//`content` mediumblob NOT NULL,
///PRIMARY KEY (`id`),
//KEY `name` (`name`),
//KEY `cache_id` (`cache_id`),
//KEY `compile_id` (`compile_id`),
//KEY `modified` (`modified`),
//KEY `expire` (`expire`)
//) ENGINE=InnoDB DEFAULT CHARSET=utf8");
}
/**
* Delete files in templates_c and cache folders
*
*/
public function cleanDirs()
{
$this->cleanCompileDir();
$this->cleanCacheDir();
if (is_dir(self::$cwd . '/templates_tmp')) {
$this->cleanDir(self::$cwd . '/templates_tmp');
}
$this->assertTrue(true);
}
/**
* Make temporary template file
*
*/
public function makeTemplateFile($name, $code)
{
if (!is_dir(self::$cwd . '/templates_tmp')) {
mkdir(self::$cwd . '/templates_tmp');
chmod(self::$cwd . '/templates_tmp', 0775);
}
$fileName = self::$cwd . '/templates_tmp/' . "{$name}";
file_put_contents($fileName, $code);
}
/**
* Delete files in templates_c folder
*
*/
public function cleanCompileDir()
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$smarty = $this->getSmarty();
if (isset($smarty)) {
$dir = $smarty->getCompileDir();
$this->cleanDir($dir);
}
}
/**
* Delete files in cache folder
*
*/
public function cleanCacheDir()
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$smarty = $this->getSmarty();
if (isset($smarty)) {
$dir = $smarty->getCacheDir();
$this->cleanDir($dir);
}
}
/**
* Delete files and sub folders
*
* @param string $dir
*/
public function cleanDir($dir)
{
$di = new RecursiveDirectoryIterator($dir);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
if (substr(basename($file->getPathname()), 0, 1) === '.' || substr((string)$file,-4) === '.txt') {
continue;
}
// directory ?
if ($file->isDir()) {
if (!$ri->isDot()) {
// delete folder if empty
@rmdir($file->getPathname());
}
} else {
unlink($file->getPathname());
}
}
}
/**
* Get PDO object
*
* @return null|PDO
*/
final public function getPDO()
{
return PHPUnit_Smarty::$pdo;
}
/**
* Remove "\r" and replace "\t" with spaces
*
* @param string $in
*
* @return mixed
*/
public function normalizeString($in)
{
if (is_string($in)) {
return str_replace(array("\r", "\t"), array('', ' '), $in);
} else {
return $in;
}
}
/**
* Remove all spaces
*
* @param string $in
*
* @return mixed
*/
public function strip($in)
{
if (is_string($in)) {
return preg_replace('/\s/', '', $in);
} else {
return $in;
}
}
/**
* Return source path
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
public function buildSourcePath($tpl, $name = null, $type = null, $dir = null)
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$name = isset($name) ? $name : $tpl->getSource()->name;
$type = isset($type) ? $type : $tpl->getSource()->type;
$dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0);
switch ($type) {
case 'file':
case 'filetest':
case 'php':
return $this->normalizePath($dir . $name);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
$this->smarty->getTemplateDir();
return sha1($name . $this->smarty->_joined_template_dir);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Build template uid
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param TemplateBase $tpl template object
* @param null|string $value
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return string
* @throws \Exception
*/
public function buildUid($tpl, $value = null, $name = null, $type = null)
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$type = isset($type) ? $type : $tpl->getSource()->type;
$name = isset($name) ? $name : $tpl->getSource()->name;
switch ($type) {
case 'php':
case 'file':
case 'filetest':
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
if ($tpl instanceof \Smarty\Smarty) {
return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) .
$this->smarty->_joined_template_dir);
}
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
return sha1($tpl->getSource()->uid . $this->smarty->_joined_template_dir);
case 'mysqltest':
case 'mysql':
return sha1($type . ':' . $name);
case 'string':
$this->smarty->getTemplateDir();
return sha1($name . $this->smarty->_joined_template_dir);
default:
throw new Exception("Unhandled source resource type '{$type}'");
}
}
/**
* Normalize path
* - remove /./ and /../
* - make it absolute
*
* @param string $path file path
*
* @return string
*/
public function normalizePath($path, $ds =null ,$absolute = true)
{
$ds = isset($ds) ? $ds : DIRECTORY_SEPARATOR;
$nds = $ds == '/' ? '\\' : '/';
$getcwd = getcwd();
// normalize $ds
$path = str_replace($nds, $ds, $path);
preg_match('#^([a-zA-Z][:])?([.]{1,2}[\/\\\]+)?([\\\])?([.]{0,2}[\/\\\]+)?([[:print:]]*)#', $path, $match);
if ($match[1] === '') {
if ($match[ 2 ] !== '' || $match[ 2 ] . $match[ 3 ] . $match[ 4 ] === '') {
$path = $getcwd . $ds . $path;
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
} else if (\Smarty\Smarty::$_IS_WINDOWS && $match[ 3 ] !== '') {
$path = substr($getcwd, 0, 2) . $path;
}
}
$path = preg_replace('#[\\\/]+([.][\\\/]+)*#', $ds, $path);
while (strrpos($path, '.' . $ds) !== false) {
$path =
preg_replace('#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', $ds,
$path);
}
$cwd = preg_replace('#[\\\/]#', $ds, $getcwd);
$path = str_ireplace($cwd,$getcwd, $path);
if (!$absolute) {
$path = preg_replace('#'.$getcwd.'#', '', $path);
}
return $path;
}
/**
* Return base name
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return null|string
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function getBasename(Template $tpl, $name = null, $type = null)
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$name = isset($name) ? $name : $tpl->getSource()->name;
$type = isset($type) ? $type : $tpl->getSource()->type;
switch ($type) {
case 'file':
case 'filetest':
if (($_pos = strpos($name, ']')) !== false) {
$name = substr($name, $_pos + 1);
}
return basename($name);
case 'mysqltest':
case 'mysql':
return $name;
case 'string':
return '';
default:
return null;
}
}
/**
* Return compiled file path
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param bool $caching caching flag
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
*
* @return string
* @throws \Exception
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function buildCompiledPath(Template $tpl, $sub = true, $caching = false, $compile_id = null,
$name = null, $type = null, $dir = null)
{
$sep = DIRECTORY_SEPARATOR;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_flag = '';
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
if ($tpl->getSource() && $tpl->getSource()->isConfig) {
$_flag = '_' . ((int) $tpl->getSmarty()->config_read_hidden + (int) $tpl->getSmarty()->config_booleanize * 2 +
(int) $tpl->getSmarty()->config_overwrite * 4);
} else {
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$_flag = '_' . ((int) $tpl->getSmarty()->merge_compiled_includes + (int) $tpl->getSmarty()->escape_html * 2);
}
$_filepath = $uid . $_flag;
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath =
substr($_filepath, 0, 2) . $sep . substr($_filepath, 2, 2) . $sep . substr($_filepath, 4, 2) . $sep .
$_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_compile_id)) {
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
}
// caching token
if ($caching) {
$_cache = '.cache';
} else {
$_cache = '';
}
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$_compile_dir = $tpl->getSmarty()->getCompileDir();
// set basename if not specified
$_basename = $this->getBasename($tpl, $name, $type);
if ($_basename === null) {
$_basename = basename(preg_replace('![^\w\/]+!', '_', $name));
}
// separate (optional) basename by dot
if ($_basename) {
$_basename = '.' . $_basename;
}
return $_compile_dir . $_filepath . '.' . $type . $_basename . $_cache . '.php';
}
/**
* Return cache file path
*
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param null|string $cache_id optional cache id
* @param null|string $compile_id optional compile id
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
* @param null|string $cacheType optional cache resource type
*
* @return string
* @throws \Exception
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function buildCachedPath(TemplateBase $tpl, $sub = true, $cache_id = null, $compile_id = null, $name = null, $type = null,
$dir = null, $cacheType = null)
{
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$cacheType = $cacheType ?? $tpl->getSmarty()->getCachingType();
switch ($cacheType) {
case 'file':
case 'filetest':
$sep = DIRECTORY_SEPARATOR;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
$_filepath = $uid;
// if use_sub_dirs, break file into directories
if ($sub) {
$_filepath =
substr($_filepath, 0, 2) . $sep . substr($_filepath, 2, 2) . $sep . substr($_filepath, 4, 2) .
$sep . $_filepath;
}
$_compile_dir_sep = $sub ? $sep : '^';
if (isset($_cache_id)) {
$_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
} else {
$_cache_id = '';
}
if (isset($_compile_id)) {
$_compile_id = $_compile_id . $_compile_dir_sep;
} else {
$_compile_id = '';
}
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
return $tpl->getSmarty()->getCacheDir() . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php';
case 'mysqltest':
case 'pdo':
case 'foobar':
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
return sha1($uid . $_cache_id . $_compile_id);
case 'memcachetest':
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
case 'apc':
$sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type);
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
return sha1($uid) . '#' . preg_replace('#[^\w\|]+#S', '_', $tpl->template_resource) . '#' . $_cache_id .
'#' . $_compile_id;
default:
throw new Exception("Unhandled cache resource type '{$cacheType}'");
}
}
/**
* prefilter to insert test number
*
* @param string $source
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
* @param \Smarty\Template $tpl
*
* @return string
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function prefilterTest($source, Template $tpl)
{
return str_replace('#test#', "test:{\$test nocache} compiled:{$tpl->getTemplateVars('test')} rendered:{\$test}",
$source);
}
/**
* Gat Smarty object
* @return null|\Smarty
*/
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
public function getSmarty(){
return $this->smarty;
}
public static function getSmartyPluginsDir(){
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
if (is_dir(__DIR__ . '/../smarty/src/plugins')) {
return __DIR__ . '/../smarty/src/plugins';
} else if(is_dir(__DIR__ . '/../libs/plugins')) {
return __DIR__ . '/../libs/plugins';
}
}
}