WIP making compile classes PSR-4

This commit is contained in:
Simon Wisselink
2022-12-01 21:54:23 +01:00
parent 53fe73b9cc
commit 9a0d46f1bc
3 changed files with 29 additions and 13 deletions

View File

@@ -8,6 +8,8 @@
* @author Uwe Tews * @author Uwe Tews
*/ */
use Smarty\Compile\Base;
/** /**
* Main abstract compiler class * Main abstract compiler class
* *
@@ -712,9 +714,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @return bool|string compiled code or false * @return bool|string compiled code or false
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
*/ */
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) private function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
{ {
/* @var Smarty_Internal_CompileBase $tagCompiler */ /* @var Base $tagCompiler */
$tagCompiler = $this->getTagCompiler($tag); $tagCompiler = $this->getTagCompiler($tag);
// compile this tag // compile this tag
return $tagCompiler === false ? false : $tagCompiler->compile($args, $this, $param1, $param2, $param3); return $tagCompiler === false ? false : $tagCompiler->compile($args, $this, $param1, $param2, $param3);
@@ -723,21 +725,35 @@ abstract class Smarty_Internal_TemplateCompilerBase
/** /**
* lazy loads internal compile plugin for tag compile objects cached for reuse. * lazy loads internal compile plugin for tag compile objects cached for reuse.
* *
* class name format: Smarty_Internal_Compile_TagName * class name format: \Smarty\Compile\TagName
* plugin filename format: Smarty_Internal_TagName.php
* *
* @param string $tag tag name * @param string $tag tag name
* *
* @return bool|\Smarty_Internal_CompileBase tag compiler object or false if not found * @return bool|\Smarty\Compile\Base tag compiler object or false if not found
*/ */
public function getTagCompiler($tag) public function getTagCompiler($tag)
{ {
static $map = [
'break' => \Smarty\Compile\BreakTag::class,
'config_load' => \Smarty\Compile\ConfigLoad::class,
'eval' => \Smarty\Compile\EvalTag::class,
'include' => \Smarty\Compile\IncludeTag::class,
'while' => \Smarty\Compile\WhileTag::class,
'private_modifier' => \Smarty\Compile\PrivateModifier::class,
];
// re-use object if already exists // re-use object if already exists
if (!isset(self::$_tag_objects[ $tag ])) { if (!isset(self::$_tag_objects[ $tag ])) {
// lazy load internal compiler plugin
$_tag = explode('_', $tag); if (isset($map[$tag])) {
$_tag = array_map('smarty_ucfirst_ascii', $_tag); $class_name = $map[$tag];
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag); } else {
$_tag = explode('_', $tag);
$_tag = array_map('smarty_ucfirst_ascii', $_tag);
$class_name = '\\Smarty\\Compile\\' . implode('_', $_tag);
}
if (class_exists($class_name) if (class_exists($class_name)
&& (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
) { ) {

View File

@@ -2,7 +2,7 @@
namespace Smarty\ParseTree; namespace Smarty\ParseTree;
/** /**
* Double quoted string inside a tag. * Double-quoted string inside a tag.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
@@ -19,7 +19,7 @@ namespace Smarty\ParseTree;
class Dq extends Base class Dq extends Base
{ {
/** /**
* Create parse tree buffer for double quoted string subtrees * Create parse tree buffer for double-quoted string subtrees
* *
* @param object $parser parser object * @param object $parser parser object
* @param Base $subtree parse tree buffer * @param Base $subtree parse tree buffer

View File

@@ -12,7 +12,7 @@ namespace Smarty\ParseTree;
*/ */
/** /**
* Raw chars as part of a double quoted string. * Raw chars as part of a double-quoted string.
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
@@ -31,7 +31,7 @@ class DqContent extends Base
} }
/** /**
* Return content as double quoted string * Return content as double-quoted string
* *
* @param \Smarty_Internal_Templateparser $parser * @param \Smarty_Internal_Templateparser $parser
* *