src/sysplugins/* to PSR-4

This commit is contained in:
Simon Wisselink
2022-12-22 21:50:01 +01:00
parent 0fc2b3726b
commit f1e7b2d46f
110 changed files with 1226 additions and 1226 deletions

View File

@@ -1,5 +1,7 @@
<?php <?php
use Smarty\Exception;
/** /**
* MySQL CacheResource * MySQL CacheResource
* CacheResource Implementation based on the Custom API to use * CacheResource Implementation based on the Custom API to use
@@ -47,14 +49,14 @@ class Smarty_CacheResource_Mysql extends \Smarty\Cacheresource\Custom
/** /**
* Smarty_CacheResource_Mysql constructor. * Smarty_CacheResource_Mysql constructor.
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct() public function __construct()
{ {
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');

View File

@@ -1,5 +1,7 @@
<?php <?php
use Smarty\Exception;
/** /**
* PDO Cache Handler * PDO Cache Handler
* Allows you to store Smarty Cache files into your db. * Allows you to store Smarty Cache files into your db.
@@ -119,12 +121,12 @@ class Smarty_CacheResource_Pdo extends \Smarty\Cacheresource\Custom
* @param string $table : table (or view) name * @param string $table : table (or view) name
* @param string $database : optional - if table is located in another db * @param string $database : optional - if table is located in another db
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct(PDO $pdo, $table, $database = null) public function __construct(PDO $pdo, $table, $database = null)
{ {
if (is_null($table)) { if (is_null($table)) {
throw new SmartyException("Table name for caching can't be null"); throw new Exception("Table name for caching can't be null");
} }
$this->pdo = $pdo; $this->pdo = $pdo;
$this->table = $table; $this->table = $table;

View File

@@ -1,5 +1,6 @@
<?php <?php
use Smarty\Exception;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Source; use Smarty\Template\Source;
@@ -35,7 +36,7 @@ class Smarty_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
$sources[ $s->uid ] = $s; $sources[ $s->uid ] = $s;
$uid .= $s->filepath; $uid .= $s->filepath;
$timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp; $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
} catch (SmartyException $e) { } catch (Exception $e) {
} }
} }
if (!$sources) { if (!$sources) {

View File

@@ -1,6 +1,7 @@
<?php <?php
use Smarty\Resource\CustomPlugin; use Smarty\Resource\CustomPlugin;
use Smarty\Exception;
/** /**
* MySQL Resource * MySQL Resource
@@ -47,14 +48,14 @@ class _MysqlPlugin extends CustomPlugin
/** /**
* Smarty_Resource_Mysql constructor. * Smarty_Resource_Mysql constructor.
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct() public function __construct()
{ {
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');

View File

@@ -1,6 +1,7 @@
<?php <?php
use Smarty\Resource\CustomPlugin; use Smarty\Resource\CustomPlugin;
use Smarty\Exception;
/** /**
* MySQL Resource * MySQL Resource
@@ -42,14 +43,14 @@ class _MysqlsPlugin extends CustomPlugin
/** /**
* Smarty_Resource_Mysqls constructor. * Smarty_Resource_Mysqls constructor.
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct() public function __construct()
{ {
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
} }

View File

@@ -8,7 +8,7 @@ resource.
> >
> The default handler is currently only invoked for file resources. It > The default handler is currently only invoked for file resources. It
> is not triggered when the resource itself cannot be found, in which > is not triggered when the resource itself cannot be found, in which
> case a SmartyException is thrown. > case a \Smarty\Exception is thrown.
<?php <?php

View File

@@ -8,7 +8,7 @@ resource.
> >
> The default handler is currently only invoked for file resources. It > The default handler is currently only invoked for file resources. It
> is not triggered when the resource itself cannot be found, in which > is not triggered when the resource itself cannot be found, in which
> case a SmartyException is thrown. > case a \Smarty\Exception is thrown.
<?php <?php

View File

@@ -77,7 +77,7 @@ to invoke your custom CacheResource implementation.
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new \Smarty\Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');

View File

@@ -63,7 +63,7 @@ example.
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new \Smarty\Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');

View File

@@ -49,7 +49,7 @@ on the functions you are supposed to provide.
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new \Smarty\Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');

View File

@@ -59,7 +59,7 @@ on the functions you are supposed to provide.
try { try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty"); $this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty", "smarty");
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new \Smarty\Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');

View File

@@ -33,7 +33,7 @@ use Smarty\Template;
* *
* @return string content re-formatted * @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_block_textformat($params, $content, Template $template, &$repeat) function smarty_block_textformat($params, $content, Template $template, &$repeat)
{ {

View File

@@ -6,6 +6,7 @@
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
use Smarty\Exception;
use Smarty\Template; use Smarty\Template;
/** /**
@@ -21,7 +22,7 @@ use Smarty\Template;
* @param array $params parameters * @param array $params parameters
* @param Template $template template object * @param Template $template template object
* *
* @throws SmartyException * @throws Exception
* @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable * @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable
*/ */
function smarty_function_fetch($params, $template) function smarty_function_fetch($params, $template)
@@ -196,7 +197,7 @@ function smarty_function_fetch($params, $template)
} else { } else {
$content = @file_get_contents($params[ 'file' ]); $content = @file_get_contents($params[ 'file' ]);
if ($content === false) { if ($content === false) {
throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'"); throw new Exception("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
} }
} }
if (!empty($params[ 'assign' ])) { if (!empty($params[ 'assign' ])) {

View File

@@ -43,7 +43,7 @@ use Smarty\Template;
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_function_html_checkboxes($params, Template $template) function smarty_function_html_checkboxes($params, Template $template)
{ {

View File

@@ -6,6 +6,7 @@
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
use Smarty\Exception;
use Smarty\Template; use Smarty\Template;
/** /**
@@ -33,7 +34,7 @@ use Smarty\Template;
* @param array $params parameters * @param array $params parameters
* @param Template $template template object * @param Template $template template object
* *
* @throws SmartyException * @throws Exception
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
*/ */
@@ -62,7 +63,7 @@ function smarty_function_html_image($params, Template $template)
if (!is_array($_val)) { if (!is_array($_val)) {
$$_key = smarty_function_escape_special_chars($_val); $$_key = smarty_function_escape_special_chars($_val);
} else { } else {
throw new SmartyException( throw new Exception(
"html_image: extra attribute '{$_key}' cannot be an array", "html_image: extra attribute '{$_key}' cannot be an array",
E_USER_NOTICE E_USER_NOTICE
); );
@@ -77,7 +78,7 @@ function smarty_function_html_image($params, Template $template)
if (!is_array($_val)) { if (!is_array($_val)) {
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
} else { } else {
throw new SmartyException( throw new Exception(
"html_image: extra attribute '{$_key}' cannot be an array", "html_image: extra attribute '{$_key}' cannot be an array",
E_USER_NOTICE E_USER_NOTICE
); );

View File

@@ -35,7 +35,7 @@ use Smarty\Template;
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_function_html_options($params, Template $template) function smarty_function_html_options($params, Template $template)
{ {

View File

@@ -43,7 +43,7 @@ use Smarty\Template;
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_function_html_radios($params, Template $template) function smarty_function_html_radios($params, Template $template)
{ {

View File

@@ -43,7 +43,7 @@ use Smarty\Template;
* @param \Smarty\Template $template * @param \Smarty\Template $template
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_function_html_select_date($params, Template $template) function smarty_function_html_select_date($params, Template $template)
{ {

View File

@@ -25,7 +25,7 @@ use Smarty\Template;
* *
* @return string * @return string
* @uses smarty_make_timestamp() * @uses smarty_make_timestamp()
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_function_html_select_time($params, Template $template) function smarty_function_html_select_time($params, Template $template)
{ {

View File

@@ -5,6 +5,9 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
use Smarty\Exception;
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* Type: modifier * Type: modifier
@@ -18,7 +21,7 @@
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* *
* @return string with compiled code * @return string with compiled code
* @throws SmartyException * @throws Exception
*/ */
function smarty_modifiercompiler_escape($params, \Smarty\Compiler\Template $compiler) function smarty_modifiercompiler_escape($params, \Smarty\Compiler\Template $compiler)
{ {
@@ -53,7 +56,7 @@ function smarty_modifiercompiler_escape($params, \Smarty\Compiler\Template $comp
$params[ 0 ] . $params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))'; ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
} }
} catch (SmartyException $e) { } catch (Exception $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback
} }
return 'smarty_modifier_escape(' . join(', ', $params) . ')'; return 'smarty_modifier_escape(' . join(', ', $params) . ')';

View File

@@ -18,7 +18,7 @@
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* *
* @return string with compiled code * @return string with compiled code
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
function smarty_modifiercompiler_wordwrap($params, \Smarty\Compiler\Template $compiler) function smarty_modifiercompiler_wordwrap($params, \Smarty\Compiler\Template $compiler)
{ {

View File

@@ -5,6 +5,9 @@
* @package Smarty * @package Smarty
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
use Smarty\Exception;
/** /**
* evaluate compiler parameter * evaluate compiler parameter
* *
@@ -13,7 +16,7 @@
* @param mixed $default value to be returned if the parameter is not present * @param mixed $default value to be returned if the parameter is not present
* *
* @return mixed evaluated value of parameter or $default * @return mixed evaluated value of parameter or $default
* @throws SmartyException if parameter is not a literal (but an expression, variable, …) * @throws Exception if parameter is not a literal (but an expression, variable, …)
* @author Rodney Rehm * @author Rodney Rehm
*/ */
function smarty_literal_compiler_param($params, $index, $default = null) function smarty_literal_compiler_param($params, $index, $default = null)
@@ -24,7 +27,7 @@ function smarty_literal_compiler_param($params, $index, $default = null)
} }
// test if param is a literal // test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) { if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new SmartyException( throw new Exception(
'$param[' . $index . '$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time' '] is not a literal and is thus not evaluatable at compile time'
); );

View File

@@ -6,6 +6,8 @@
* @subpackage PluginsShared * @subpackage PluginsShared
*/ */
use Smarty\Exception;
/** /**
* Multibyte string replace * Multibyte string replace
* *
@@ -72,7 +74,7 @@ function smarty_mb_str_replace($search, $replace, $subject, &$count = 0)
// This exception is thrown if call to mb_split failed. // This exception is thrown if call to mb_split failed.
// Usually it happens, when $search or $replace are not valid for given mb_regex_encoding(). // Usually it happens, when $search or $replace are not valid for given mb_regex_encoding().
// There may be other cases for it to fail, please file an issue if you find a reproducible one. // There may be other cases for it to fail, please file an issue if you find a reproducible one.
throw new SmartyException("Source string is not a valid $current_charset sequence (probably)"); throw new Exception("Source string is not a valid $current_charset sequence (probably)");
} }
$count = count($parts) - 1; $count = count($parts) - 1;

View File

@@ -193,7 +193,6 @@ abstract class Base
* @param Smarty $smarty Smarty object * @param Smarty $smarty Smarty object
* @param string $type name of the cache resource * @param string $type name of the cache resource
* *
* @throws SmartyException
* @return Base Cache Resource Handler * @return Base Cache Resource Handler
*/ */
public static function load(Smarty $smarty, $type = null) public static function load(Smarty $smarty, $type = null)

View File

@@ -233,7 +233,7 @@ abstract class Custom extends Base
* @param integer $exp_time expiration time (number of seconds, not timestamp) * @param integer $exp_time expiration time (number of seconds, not timestamp)
* *
* @return int number of cache files deleted * @return int number of cache files deleted
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function clear(\Smarty\Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) public function clear(\Smarty\Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{ {

View File

@@ -122,7 +122,7 @@ class File extends Base
* @param string $content content to cache * @param string $content content to cache
* *
* @return bool success * @return bool success
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function storeCachedContent(Template $_template, $content) public function storeCachedContent(Template $_template, $content)
{ {

View File

@@ -207,7 +207,7 @@ abstract class KeyValueStore extends Base
* @param integer $exp_time expiration time [being ignored] * @param integer $exp_time expiration time [being ignored]
* *
* @return int number of cache files deleted [always -1] * @return int number of cache files deleted [always -1]
* @throws \SmartyException * @throws \Smarty\Exception
* @uses buildCachedFilepath() to generate the CacheID * @uses buildCachedFilepath() to generate the CacheID
* @uses invalidate() to mark CacheIDs parent chain as outdated * @uses invalidate() to mark CacheIDs parent chain as outdated
* @uses delete() to remove CacheID from cache * @uses delete() to remove CacheID from cache
@@ -229,7 +229,7 @@ abstract class KeyValueStore extends Base
* @param string $resource_name template name * @param string $resource_name template name
* *
* @return string filepath of cache file * @return string filepath of cache file
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
protected function getTemplateUid(Smarty $smarty, $resource_name) protected function getTemplateUid(Smarty $smarty, $resource_name)
{ {

View File

@@ -27,7 +27,7 @@ class Append extends Assign
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null) public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{ {

View File

@@ -49,7 +49,7 @@ class Assign extends CompileBase
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null) public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{ {

View File

@@ -206,7 +206,7 @@ abstract class Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
abstract public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null); abstract public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null);
} }

View File

@@ -48,7 +48,7 @@ class BreakTag extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null) public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{ {
@@ -73,7 +73,7 @@ class BreakTag extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return array * @return array
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function checkLevels($args, \Smarty\Compiler\Template $compiler) { public function checkLevels($args, \Smarty\Compiler\Template $compiler) {
static $_is_loopy = ['for' => true, 'foreach' => true, 'while' => true, 'section' => true]; static $_is_loopy = ['for' => true, 'foreach' => true, 'while' => true, 'section' => true];

View File

@@ -49,7 +49,7 @@ class Child extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -71,7 +71,7 @@ class ConfigLoad extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -20,7 +20,7 @@ class ElseIfTag extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -51,8 +51,8 @@ class ExtendsTag extends Inheritance {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes
@@ -98,8 +98,8 @@ class ExtendsTag extends Inheritance {
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* @param null|string $template optional inheritance parent template * @param null|string $template optional inheritance parent template
* *
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) { private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) {
$inlineUids = ''; $inlineUids = '';
@@ -124,8 +124,8 @@ class ExtendsTag extends Inheritance {
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* @param string $template subtemplate name * @param string $template subtemplate name
* *
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function compileInclude(\Smarty\Compiler\Template $compiler, $template) { private function compileInclude(\Smarty\Compiler\Template $compiler, $template) {
$compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( $compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag(

View File

@@ -25,7 +25,7 @@ class ForeachClose extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--; $compiler->loopNesting--;

View File

@@ -80,7 +80,7 @@ abstract class ForeachSection extends Base {
* @param array $attributes * @param array $attributes
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
protected function scanForProperties($attributes, \Smarty\Compiler\Template $compiler) { protected function scanForProperties($attributes, \Smarty\Compiler\Template $compiler) {
$this->propertyPreg = '~('; $this->propertyPreg = '~(';
@@ -162,7 +162,7 @@ abstract class ForeachSection extends Base {
* *
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function matchParentTemplateSource(\Smarty\Compiler\Template $compiler) { private function matchParentTemplateSource(\Smarty\Compiler\Template $compiler) {
// search parent compiler template source // search parent compiler template source
@@ -194,7 +194,7 @@ abstract class ForeachSection extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compileSpecialVariable(\Smarty\Compiler\Template $compiler, $parameter) { public function compileSpecialVariable(\Smarty\Compiler\Template $compiler, $parameter) {
$tag = smarty_strtolower_ascii(trim($parameter[0], '"\'')); $tag = smarty_strtolower_ascii(trim($parameter[0], '"\''));

View File

@@ -78,8 +78,8 @@ class ForeachTag extends ForeachSection {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++; $compiler->loopNesting++;

View File

@@ -43,7 +43,7 @@ class FunctionTag extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return bool true * @return bool true
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -20,7 +20,7 @@ class IfTag extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -79,8 +79,8 @@ class IncludeTag extends Base {
* *
* @return string * @return string
* @throws \Exception * @throws \Exception
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$uid = $t_hash = null; $uid = $t_hash = null;
@@ -292,7 +292,7 @@ class IncludeTag extends Base {
* *
* @return bool * @return bool
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function compileInlineTemplate( private function compileInlineTemplate(
Template $compiler, Template $compiler,

View File

@@ -52,8 +52,8 @@ class Insert extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -28,7 +28,7 @@ class Ldelim extends Base {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);

View File

@@ -45,8 +45,8 @@ class PrivateBlockPlugin extends Base {
* @param string $function PHP function name * @param string $function PHP function name
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
if (!isset($tag[5]) || substr($tag, -5) !== 'close') { if (!isset($tag[5]) || substr($tag, -5) !== 'close') {
@@ -64,7 +64,7 @@ class PrivateBlockPlugin extends Base {
$callback = "\$_block_plugin{$this->nesting}{$callback[1]}"; $callback = "\$_block_plugin{$this->nesting}{$callback[1]}";
} }
if (isset($callable)) { if (isset($callable)) {
$output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n"; $output .= "if (!is_callable({$callable})) {\nthrow new \\Smarty\\Exception('block tag \'{$tag}\' not callable or registered');\n}\n";
} }
$output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>"; $output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>";
$this->openTag($compiler, $tag, [$_params, $compiler->nocache, $callback]); $this->openTag($compiler, $tag, [$_params, $compiler->nocache, $callback]);

View File

@@ -47,8 +47,8 @@ class PrivateFunctionPlugin extends Base {
* @param string $function PHP function name * @param string $function PHP function name
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -28,8 +28,8 @@ class PrivateModifier extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -38,8 +38,8 @@ class PrivateObjectFunction extends Base {
* @param string $function name of method to call * @param string $function name of method to call
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -45,7 +45,7 @@ class PrivatePrintExpression extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes
@@ -138,7 +138,7 @@ class PrivatePrintExpression extends Base {
* @param string $output embedded output * @param string $output embedded output
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function compile_variable_filter(\Smarty\Compiler\Template $compiler, $name, $output) { private function compile_variable_filter(\Smarty\Compiler\Template $compiler, $name, $output) {
$function = $compiler->getPlugin($name, 'variablefilter'); $function = $compiler->getPlugin($name, 'variablefilter');

View File

@@ -38,8 +38,8 @@ class PrivateRegisteredFunction extends Base {
* @param string $tag name of function * @param string $tag name of function
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes // check and get attributes

View File

@@ -32,7 +32,7 @@ class PrivateSpecialVariable extends Base {
* @param $parameter * @param $parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));

View File

@@ -28,7 +28,7 @@ class Rdelim extends Ldelim {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
parent::compile($args, $compiler); parent::compile($args, $compiler);

View File

@@ -81,8 +81,8 @@ class Section extends ForeachSection {
* @param \Smarty\Compiler\Template $compiler compiler object * @param \Smarty\Compiler\Template $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++; $compiler->loopNesting++;

View File

@@ -20,7 +20,7 @@ class WhileTag extends Base {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++; $compiler->loopNesting++;

View File

@@ -14,7 +14,7 @@ use Smarty;
use Smarty_Internal_ConfigFileLexer; use Smarty_Internal_ConfigFileLexer;
use Smarty_Internal_ConfigFileParser; use Smarty_Internal_ConfigFileParser;
use Smarty\Template; use Smarty\Template;
use SmartyCompilerException; use Smarty\CompilerException;
/** /**
* Main config file compiler class * Main config file compiler class
@@ -96,7 +96,7 @@ class ConfigFile {
* @param Template $template * @param Template $template
* *
* @return bool true if compiling succeeded, false if it failed * @return bool true if compiling succeeded, false if it failed
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function compileTemplate(Template $template) { public function compileTemplate(Template $template) {
$this->template = $template; $this->template = $template;
@@ -174,7 +174,7 @@ class ConfigFile {
* *
* @param string $args individual error message or null * @param string $args individual error message or null
* *
* @throws SmartyCompilerException * @throws CompilerException
*/ */
public function trigger_config_file_error($args = null) { public function trigger_config_file_error($args = null) {
// get config source line which has error // get config source line which has error
@@ -203,6 +203,6 @@ class ConfigFile {
// output parser error message // output parser error message
$error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect); $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
} }
throw new SmartyCompilerException($error_text); throw new CompilerException($error_text);
} }
} }

View File

@@ -14,8 +14,8 @@ use Smarty;
use Smarty\Compile\Base; use Smarty\Compile\Base;
use Smarty\Compile\ExtendsTag; use Smarty\Compile\ExtendsTag;
use Smarty_Internal_Templateparser; use Smarty_Internal_Templateparser;
use SmartyCompilerException; use Smarty\CompilerException;
use SmartyException; use Smarty\Exception;
/** /**
* Class SmartyTemplateCompiler * Class SmartyTemplateCompiler
@@ -468,7 +468,7 @@ class Template {
* @param string $code compiled code * @param string $code compiled code
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function postFilter($code) { public function postFilter($code) {
// run post filter if on code // run post filter if on code
@@ -485,7 +485,7 @@ class Template {
* @param string $_content template source * @param string $_content template source
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function preFilter($_content) { public function preFilter($_content) {
// run pre filter if required // run pre filter if required
@@ -510,8 +510,8 @@ class Template {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws SmartyException * @throws Exception
* @throws SmartyCompilerException * @throws CompilerException
*/ */
public function compileTag($tag, $args, $parameter = []) { public function compileTag($tag, $args, $parameter = []) {
$this->prefixCodeStack[] = $this->prefix_code; $this->prefixCodeStack[] = $this->prefix_code;
@@ -562,7 +562,7 @@ class Template {
* @param array $parameter * @param array $parameter
* *
* @return string * @return string
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function compilePHPFunctionCall($name, $parameter) { public function compilePHPFunctionCall($name, $parameter) {
if (!$this->smarty->security_policy || $this->smarty->security_policy->isTrustedPhpFunction($name, $this)) { if (!$this->smarty->security_policy || $this->smarty->security_policy->isTrustedPhpFunction($name, $this)) {
@@ -704,7 +704,7 @@ class Template {
* @param mixed $param3 optional parameter * @param mixed $param3 optional parameter
* *
* @return bool|string compiled code or false * @return bool|string compiled code or false
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
private function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) { private function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) {
/* @var Base $tagCompiler */ /* @var Base $tagCompiler */
@@ -860,7 +860,7 @@ class Template {
* @param string $plugin_type type of plugin * @param string $plugin_type type of plugin
* *
* @return bool true if found * @return bool true if found
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function getPluginFromDefaultHandler($tag, $plugin_type) { public function getPluginFromDefaultHandler($tag, $plugin_type) {
$callback = null; $callback = null;
@@ -1003,7 +1003,7 @@ class Template {
* @param array $validScopes * @param array $validScopes
* *
* @return int|string * @return int|string
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function convertScope($_attr, $validScopes) { public function convertScope($_attr, $validScopes) {
$_scope = 0; $_scope = 0;
@@ -1048,7 +1048,7 @@ class Template {
* @param string $line line-number * @param string $line line-number
* @param null|bool $tagline if true the line number of last tag * @param null|bool $tagline if true the line number of last tag
* *
* @throws \SmartyCompilerException when an unexpected token is found * @throws \Smarty\CompilerException when an unexpected token is found
*/ */
public function trigger_template_error($args = null, $line = null, $tagline = null) { public function trigger_template_error($args = null, $line = null, $tagline = null) {
$lex = $this->parser->lex; $lex = $this->parser->lex;
@@ -1113,7 +1113,7 @@ class Template {
echo ob_get_clean(); echo ob_get_clean();
flush(); flush();
} }
$e = new SmartyCompilerException( $e = new CompilerException(
$error_text, $error_text,
0, 0,
$this->template->source->filepath, $this->template->source->filepath,
@@ -1205,7 +1205,7 @@ class Template {
* leave double quoted string * leave double quoted string
* - throw exception if block in string was not closed * - throw exception if block in string was not closed
* *
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
public function leaveDoubleQuote() { public function leaveDoubleQuote() {
if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) { if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) {
@@ -1349,8 +1349,8 @@ class Template {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws SmartyException * @throws Exception
* @throws SmartyCompilerException * @throws CompilerException
*/ */
private function compileTag2($tag, $args, $parameter) { private function compileTag2($tag, $args, $parameter) {
$plugin_type = ''; $plugin_type = '';
@@ -1494,7 +1494,7 @@ class Template {
return $plugin_object->compile($args, $this); return $plugin_object->compile($args, $this);
} }
} }
throw new SmartyException("Plugin '{$tag}' not callable"); throw new Exception("Plugin '{$tag}' not callable");
} else { } else {
if ($function = $this->getPlugin($tag, $plugin_type)) { if ($function = $this->getPlugin($tag, $plugin_type)) {
if (!isset($this->smarty->security_policy) if (!isset($this->smarty->security_policy)
@@ -1628,7 +1628,7 @@ class Template {
return $plugin_object->compile($args, $this); return $plugin_object->compile($args, $this);
} }
} }
throw new SmartyException("Plugin '{$tag}' not callable"); throw new Exception("Plugin '{$tag}' not callable");
} }
$this->trigger_template_error("unknown tag '{$tag}'", null, true); $this->trigger_template_error("unknown tag '{$tag}'", null, true);
} }
@@ -1641,7 +1641,7 @@ class Template {
* @param bool $isTemplateSource * @param bool $isTemplateSource
* *
* @return bool true if compiling succeeded, false if it failed * @return bool true if compiling succeeded, false if it failed
* @throws \SmartyCompilerException * @throws \Smarty\CompilerException
*/ */
protected function doCompile($_content, $isTemplateSource = false) { protected function doCompile($_content, $isTemplateSource = false) {
/* here is where the compiling takes place. Smarty /* here is where the compiling takes place. Smarty

73
src/CompilerException.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
namespace Smarty;
/**
* Smarty compiler exception class
*
* @package Smarty
*/
class CompilerException extends Exception {
/**
* The constructor of the exception
*
* @param string $message The Exception message to throw.
* @param int $code The Exception code.
* @param string|null $filename The filename where the exception is thrown.
* @param int|null $line The line number where the exception is thrown.
* @param Throwable|null $previous The previous exception used for the exception chaining.
*/
public function __construct(
string $message = "",
int $code = 0,
?string $filename = null,
?int $line = null,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
// These are optional parameters, should be be overridden only when present!
if ($filename) {
$this->file = $filename;
}
if ($line) {
$this->line = $line;
}
}
/**
* @return string
*/
public function __toString() {
return ' --> Smarty Compiler: ' . $this->message . ' <-- ';
}
/**
* @param int $line
*/
public function setLine($line) {
$this->line = $line;
}
/**
* The template source snippet relating to the error
*
* @type string|null
*/
public $source = null;
/**
* The raw text of the error message
*
* @type string|null
*/
public $desc = null;
/**
* The resource identifier or template name
*
* @type string|null
*/
public $template = null;
}

View File

@@ -48,7 +48,7 @@ abstract class Data
/** /**
* parent template (if any) * parent template (if any)
* *
* @var Smarty|Template|Smarty_Data * @var Smarty|Template|DataObject
*/ */
public $parent = null; public $parent = null;
@@ -126,7 +126,7 @@ abstract class Data
if ($tpl_var !== '' && isset($value)) { if ($tpl_var !== '' && isset($value)) {
if (!isset($this->tpl_vars[ $tpl_var ])) { if (!isset($this->tpl_vars[ $tpl_var ])) {
$tpl_var_inst = $this->_getVariable($tpl_var, null, true, false); $tpl_var_inst = $this->_getVariable($tpl_var, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { if ($tpl_var_inst instanceof UndefinedVariable) {
$this->tpl_vars[ $tpl_var ] = new \Smarty\Variable(null, $nocache); $this->tpl_vars[ $tpl_var ] = new \Smarty\Variable(null, $nocache);
} else { } else {
$this->tpl_vars[ $tpl_var ] = clone $tpl_var_inst; $this->tpl_vars[ $tpl_var ] = clone $tpl_var_inst;
@@ -313,7 +313,7 @@ abstract class Data
// force a notice // force a notice
$x = $$varName; $x = $$varName;
} }
return new Smarty_Undefined_Variable; return new UndefinedVariable;
} }
/** /**
@@ -566,12 +566,12 @@ abstract class Data
/** /**
* gets a stream variable * gets a stream variable
* *
* @api Smarty::getStreamVariable()
*
* @param string $variable the stream of the variable * @param string $variable the stream of the variable
* *
* @return mixed * @return mixed
* @throws \SmartyException * @throws \Smarty\Exception
*@api Smarty::getStreamVariable()
*
*/ */
public function getStreamVariable($variable) public function getStreamVariable($variable)
{ {
@@ -586,7 +586,7 @@ abstract class Data
} }
$smarty = $this->smarty ?? $this; $smarty = $this->smarty ?? $this;
if ($smarty->error_unassigned) { if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"'); throw new Exception('Undefined stream variable "' . $variable . '"');
} else { } else {
return null; return null;
} }

71
src/DataObject.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
/**
* Smarty Plugin Data
* This file contains the data object
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
namespace Smarty;
use Smarty\Exception;
/**
* class for the Smarty data object
* The Smarty data object will hold Smarty variables in the current scope
*
* @package Smarty
* @subpackage Template
*/
class DataObject extends Data {
/**
* Counter
*
* @var int
*/
public static $count = 0;
/**
* Data block name
*
* @var string
*/
public $dataObjectName = '';
/**
* Smarty object
*
* @var Smarty
*/
public $smarty = null;
/**
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty|Template $smarty global smarty instance
* @param string $name optional data block name
*
* @throws Exception
*/
public function __construct($_parent = null, $smarty = null, $name = null) {
parent::__construct();
self::$count++;
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
$this->smarty = $smarty;
if (is_object($_parent)) {
// when object set up back pointer
$this->parent = $_parent;
} elseif (is_array($_parent)) {
// set up variable values
foreach ($_parent as $_key => $_val) {
$this->tpl_vars[$_key] = new Variable($_val);
}
} elseif ($_parent !== null) {
throw new Exception('Wrong type for template variables');
}
}
}

View File

@@ -188,7 +188,7 @@ class Debug extends Data
* @param bool $full * @param bool $full
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function display_debug($obj, $full = false) public function display_debug($obj, $full = false)
{ {
@@ -254,7 +254,7 @@ class Debug extends Data
/** /**
* Recursively gets variables from all template/data scopes * Recursively gets variables from all template/data scopes
* *
* @param \Smarty\Template|\Smarty_Data $obj object to debug * @param \Smarty\Template|\Smarty\DataObject $obj object to debug
* *
* @return \StdClass * @return \StdClass
*/ */

16
src/Exception.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace Smarty;
/**
* Smarty exception class
*/
class Exception extends \Exception {
/**
* @return string
*/
public function __toString() {
return ' --> Smarty: ' . $this->message . ' <-- ';
}
}

View File

@@ -64,8 +64,8 @@ abstract class BasePlugin
* @param \Smarty $smarty smarty object * @param \Smarty $smarty smarty object
* @param string $type name of the resource * @param string $type name of the resource
* *
* @throws \SmartyException
* @return BasePlugin Resource Handler * @return BasePlugin Resource Handler
*@throws \Smarty\Exception
*/ */
public static function load(\Smarty $smarty, $type) public static function load(\Smarty $smarty, $type)
{ {
@@ -108,7 +108,7 @@ abstract class BasePlugin
} }
// TODO: try default_(template|config)_handler // TODO: try default_(template|config)_handler
// give up // give up
throw new \SmartyException("Unknown resource type '{$type}'"); throw new \Smarty\Exception("Unknown resource type '{$type}'");
} }
/** /**
@@ -143,7 +143,7 @@ abstract class BasePlugin
* name of * name of
* *
* @return string unique resource name * @return string unique resource name
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public static function getUniqueTemplateName($obj, $template_resource) public static function getUniqueTemplateName($obj, $template_resource)
{ {
@@ -171,7 +171,7 @@ abstract class BasePlugin
* @param string $template_resource resource identifier * @param string $template_resource resource identifier
* *
* @return \Smarty\Template\Source Source Object * @return \Smarty\Template\Source Source Object
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public static function source( public static function source(
\Smarty\Template $_template = null, \Smarty\Template $_template = null,
@@ -187,7 +187,7 @@ abstract class BasePlugin
* @param \Smarty\Template\Source $source source object * @param \Smarty\Template\Source $source source object
* *
* @return string template source * @return string template source
* @throws \SmartyException if source cannot be loaded * @throws \Smarty\Exception if source cannot be loaded
*/ */
abstract public function getContent(\Smarty\Template\Source $source); abstract public function getContent(\Smarty\Template\Source $source);

View File

@@ -11,7 +11,7 @@ namespace Smarty\Resource;
use Smarty; use Smarty;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Source; use Smarty\Template\Source;
use SmartyException; use Smarty\Exception;
/** /**
* Smarty Resource Plugin * Smarty Resource Plugin
@@ -72,14 +72,14 @@ abstract class CustomPlugin extends BasePlugin {
* @param Source $source source object * @param Source $source source object
* *
* @return string template source * @return string template source
* @throws SmartyException if source cannot be loaded * @throws Exception if source cannot be loaded
*/ */
public function getContent(Source $source) { public function getContent(Source $source) {
$this->fetch($source->name, $content, $timestamp); $this->fetch($source->name, $content, $timestamp);
if (isset($content)) { if (isset($content)) {
return $content; return $content;
} }
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); throw new Exception("Unable to read template {$source->type} '{$source->name}'");
} }
/** /**

View File

@@ -27,7 +27,7 @@ class ExtendsPlugin extends BasePlugin
* @param \Smarty\Template\Source $source source object * @param \Smarty\Template\Source $source source object
* @param \Smarty\Template $_template template object * @param \Smarty\Template $_template template object
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null) public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
{ {
@@ -40,7 +40,7 @@ class ExtendsPlugin extends BasePlugin
/* @var \Smarty\Template\Source $_s */ /* @var \Smarty\Template\Source $_s */
$_s = \Smarty\Template\Source::load(null, $smarty, $component); $_s = \Smarty\Template\Source::load(null, $smarty, $component);
if ($_s->type === 'php') { if ($_s->type === 'php') {
throw new \SmartyException("Resource type {$_s->type} cannot be used with the extends resource type"); throw new \Smarty\Exception("Resource type {$_s->type} cannot be used with the extends resource type");
} }
$sources[ $_s->uid ] = $_s; $sources[ $_s->uid ] = $_s;
$uid .= $_s->filepath; $uid .= $_s->filepath;
@@ -78,12 +78,12 @@ class ExtendsPlugin extends BasePlugin
* @param \Smarty\Template\Source $source source object * @param \Smarty\Template\Source $source source object
* *
* @return string template source * @return string template source
* @throws \SmartyException if source cannot be loaded * @throws \Smarty\Exception if source cannot be loaded
*/ */
public function getContent(\Smarty\Template\Source $source) public function getContent(\Smarty\Template\Source $source)
{ {
if (!$source->exists) { if (!$source->exists) {
throw new \SmartyException("Unable to load template '{$source->type}:{$source->name}'"); throw new \Smarty\Exception("Unable to load template '{$source->type}:{$source->name}'");
} }
$_components = array_reverse($source->components); $_components = array_reverse($source->components);
$_content = ''; $_content = '';

View File

@@ -12,7 +12,7 @@ namespace Smarty\Resource;
use Smarty; use Smarty;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Source; use Smarty\Template\Source;
use SmartyException; use Smarty\Exception;
/** /**
* Smarty Internal Plugin Resource File * Smarty Internal Plugin Resource File
@@ -29,7 +29,7 @@ class FilePlugin extends BasePlugin {
* @param Source $source source object * @param Source $source source object
* @param Template $_template template object * @param Template $_template template object
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, Template $_template = null) {
$source->filepath = $this->buildFilepath($source, $_template); $source->filepath = $this->buildFilepath($source, $_template);
@@ -68,13 +68,13 @@ class FilePlugin extends BasePlugin {
* @param Source $source source object * @param Source $source source object
* *
* @return string template source * @return string template source
* @throws SmartyException if source cannot be loaded * @throws Exception if source cannot be loaded
*/ */
public function getContent(Source $source) { public function getContent(Source $source) {
if ($source->exists) { if ($source->exists) {
return file_get_contents($source->filepath); return file_get_contents($source->filepath);
} }
throw new SmartyException( throw new Exception(
'Unable to read ' . ($source->isConfig ? 'config' : 'template') . 'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
" {$source->type} '{$source->name}'" " {$source->type} '{$source->name}'"
); );
@@ -98,7 +98,7 @@ class FilePlugin extends BasePlugin {
* @param Template $_template template object * @param Template $_template template object
* *
* @return string fully qualified filepath * @return string fully qualified filepath
* @throws SmartyException * @throws Exception
*/ */
protected function buildFilepath(Source $source, Template $_template = null) { protected function buildFilepath(Source $source, Template $_template = null) {
$file = $source->name; $file = $source->name;
@@ -112,7 +112,7 @@ class FilePlugin extends BasePlugin {
&& preg_match('#^[.]{1,2}[\\\/]#', $file) && preg_match('#^[.]{1,2}[\\\/]#', $file)
) { ) {
if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') { if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') {
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); throw new Exception("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
} }
// normalize path // normalize path
$path = $path =

View File

@@ -5,7 +5,7 @@ namespace Smarty\Resource;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Source; use Smarty\Template\Source;
use Smarty\Template\Compiled; use Smarty\Template\Compiled;
use SmartyException; use Smarty\Exception;
/** /**
* Smarty Internal Plugin Resource PHP * Smarty Internal Plugin Resource PHP
@@ -52,13 +52,13 @@ class PhpPlugin extends FilePlugin {
* @param Source $source source object * @param Source $source source object
* *
* @return string template source * @return string template source
* @throws SmartyException if source cannot be loaded * @throws Exception if source cannot be loaded
*/ */
public function getContent(Source $source) { public function getContent(Source $source) {
if ($source->exists) { if ($source->exists) {
return ''; return '';
} }
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); throw new Exception("Unable to read template {$source->type} '{$source->name}'");
} }
/** /**
@@ -86,14 +86,14 @@ class PhpPlugin extends FilePlugin {
* @param Template $_template template object * @param Template $_template template object
* *
* @return void * @return void
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled * @throws Exception if template cannot be loaded or allow_php_templates is disabled
*/ */
public function renderUncompiled(Source $source, Template $_template) { public function renderUncompiled(Source $source, Template $_template) {
if (!$source->smarty->allow_php_templates) { if (!$source->smarty->allow_php_templates) {
throw new SmartyException('PHP templates are disabled'); throw new Exception('PHP templates are disabled');
} }
if (!$source->exists) { if (!$source->exists) {
throw new SmartyException( throw new Exception(
"Unable to load template '{$source->type}:{$source->name}'" . "Unable to load template '{$source->type}:{$source->name}'" .
($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '') ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '')
); );

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace Smarty; namespace Smarty\Runtime;
/** /**
* Smarty {block} tag class * Smarty {block} tag class

View File

@@ -101,7 +101,7 @@ class CaptureRuntime {
* *
* @param \Smarty\Template $_template * @param \Smarty\Template $_template
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function close(Template $_template) { public function close(Template $_template) {
if ($this->captureCount) { if ($this->captureCount) {
@@ -124,10 +124,10 @@ class CaptureRuntime {
* *
* @param \Smarty\Template $_template * @param \Smarty\Template $_template
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function error(Template $_template) { public function error(Template $_template) {
throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'"); throw new \Smarty\Exception("Not matching {capture}{/capture} in '{$_template->template_resource}'");
} }
/** /**
@@ -151,7 +151,7 @@ class CaptureRuntime {
* *
* @param \Smarty\Template $_template * @param \Smarty\Template $_template
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function endRender(Template $_template) { public function endRender(Template $_template) {
if ($this->captureCount) { if ($this->captureCount) {

View File

@@ -3,7 +3,7 @@
namespace Smarty\Runtime; namespace Smarty\Runtime;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Source; use Smarty\Template\Source;
use SmartyException; use Smarty\Exception;
/** /**
* Inheritance Runtime Methods processBlock, endChild, init * Inheritance Runtime Methods processBlock, endChild, init
@@ -29,7 +29,7 @@ class InheritanceRuntime {
/** /**
* Array of root child {block} objects * Array of root child {block} objects
* *
* @var \Smarty\Block[] * @var \Smarty\Runtime\Block[]
*/ */
public $childRoot = []; public $childRoot = [];
@@ -104,7 +104,7 @@ class InheritanceRuntime {
* @param null|string $func function call name of inline template * @param null|string $func function call name of inline template
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function endChild(Template $tpl, $template = null, $uid = null, $func = null) { public function endChild(Template $tpl, $template = null, $uid = null, $func = null) {
--$this->inheritanceLevel; --$this->inheritanceLevel;
@@ -140,7 +140,7 @@ class InheritanceRuntime {
* @param string $name * @param string $name
* @param int|null $tplIndex index of outer level {block} if nested * @param int|null $tplIndex index of outer level {block} if nested
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function instanceBlock(Template $tpl, $className, $name, $tplIndex = null) { public function instanceBlock(Template $tpl, $className, $name, $tplIndex = null) {
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex); $block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
@@ -162,15 +162,15 @@ class InheritanceRuntime {
* Goto child block or render this * Goto child block or render this
* *
* @param Template $tpl * @param Template $tpl
* @param \Smarty\Block $block * @param \Smarty\Runtime\Block $block
* @param \Smarty\Block|null $parent * @param \Smarty\Runtime\Block|null $parent
* *
* @throws SmartyException * @throws Exception
*/ */
public function process( public function process(
Template $tpl, Template $tpl,
\Smarty\Block $block, \Smarty\Runtime\Block $block,
\Smarty\Block $parent = null \Smarty\Runtime\Block $parent = null
) { ) {
if ($block->hide && !isset($block->child)) { if ($block->hide && !isset($block->child)) {
return; return;
@@ -206,12 +206,12 @@ class InheritanceRuntime {
* Render child on \$smarty.block.child * Render child on \$smarty.block.child
* *
* @param Template $tpl * @param Template $tpl
* @param \Smarty\Block $block * @param \Smarty\Runtime\Block $block
* *
* @return null|string block content * @return null|string block content
* @throws SmartyException * @throws Exception
*/ */
public function callChild(Template $tpl, \Smarty\Block $block) { public function callChild(Template $tpl, \Smarty\Runtime\Block $block) {
if (isset($block->child)) { if (isset($block->child)) {
$this->process($tpl, $block->child, $block); $this->process($tpl, $block->child, $block);
} }
@@ -221,27 +221,27 @@ class InheritanceRuntime {
* Render parent block on \$smarty.block.parent or {block append/prepend} * Render parent block on \$smarty.block.parent or {block append/prepend}
* *
* @param Template $tpl * @param Template $tpl
* @param \Smarty\Block $block * @param \Smarty\Runtime\Block $block
* @param string $tag * @param string $tag
* *
* @return null|string block content * @return null|string block content
* @throws SmartyException * @throws Exception
*/ */
public function callParent(Template $tpl, \Smarty\Block $block, $tag) { public function callParent(Template $tpl, \Smarty\Runtime\Block $block, $tag) {
if (isset($block->parent)) { if (isset($block->parent)) {
$this->callBlock($block->parent, $tpl); $this->callBlock($block->parent, $tpl);
} else { } else {
throw new SmartyException("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); throw new Exception("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
} }
} }
/** /**
* render block * render block
* *
* @param \Smarty\Block $block * @param \Smarty\Runtime\Block $block
* @param Template $tpl * @param Template $tpl
*/ */
public function callBlock(\Smarty\Block $block, Template $tpl) { public function callBlock(\Smarty\Runtime\Block $block, Template $tpl) {
$this->sourceStack[] = $tpl->source; $this->sourceStack[] = $tpl->source;
$tpl->source = $this->sources[$block->tplIndex]; $tpl->source = $this->sources[$block->tplIndex];
$block->callBlock($tpl); $block->callBlock($tpl);

View File

@@ -19,14 +19,14 @@ class MakeNocacheRuntime {
* @param \Smarty\Template $tpl * @param \Smarty\Template $tpl
* @param string $var variable name * @param string $var variable name
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function save(Template $tpl, $var) { public function save(Template $tpl, $var) {
if (isset($tpl->tpl_vars[$var])) { if (isset($tpl->tpl_vars[$var])) {
$export = $export =
preg_replace('/^\\\\Smarty\\\\Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[$var], true)); preg_replace('/^\\\\Smarty\\\\Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[$var], true));
if (preg_match('/(\w+)::__set_state/', $export, $match)) { if (preg_match('/(\w+)::__set_state/', $export, $match)) {
throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'"); throw new \Smarty\Exception("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
} }
echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " . echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " .
addcslashes("\$_smarty_tpl->smarty->getRuntime('MakeNocache')->store(\$_smarty_tpl, '{$var}', ", '\\') . addcslashes("\$_smarty_tpl->smarty->getRuntime('MakeNocache')->store(\$_smarty_tpl, '{$var}', ", '\\') .

View File

@@ -21,7 +21,7 @@ class TplFunctionRuntime {
* @param array $params parameter array * @param array $params parameter array
* @param bool $nocache true if called nocache * @param bool $nocache true if called nocache
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function callTemplateFunction(Template $tpl, $name, $params, $nocache) { public function callTemplateFunction(Template $tpl, $name, $params, $nocache) {
$funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null); $funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null);
@@ -49,7 +49,7 @@ class TplFunctionRuntime {
return; return;
} }
} }
throw new SmartyException("Unable to find template function '{$name}'"); throw new \Smarty\Exception("Unable to find template function '{$name}'");
} }
/** /**

667
src/Security.php Normal file
View File

@@ -0,0 +1,667 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage Security
* @author Uwe Tews
*/
/**
* FIXME: Smarty_Security API
* - getter and setter instead of public properties would allow cultivating an internal cache properly
* - current implementation of isTrustedResourceDir() assumes that Smarty::$template_dir and Smarty::$config_dir
* are immutable the cache is killed every time either of the variables change. That means that two distinct
* Smarty objects with differing
* $template_dir or $config_dir should NOT share the same Smarty_Security instance,
* as this would lead to (severe) performance penalty! how should this be handled?
*/
namespace Smarty;
use Smarty\Exception;
/**
* This class does contain the security settings
*/
#[\AllowDynamicProperties]
class Security {
/**
* This is the list of template directories that are considered secure.
* $template_dir is in this list implicitly.
*
* @var array
*/
public $secure_dir = [];
/**
* This is an array of directories where trusted php scripts reside.
* {@link $security} is disabled during their inclusion/execution.
*
* @var array
*/
public $trusted_dir = [];
/**
* List of regular expressions (PCRE) that include trusted URIs
*
* @var array
*/
public $trusted_uri = [];
/**
* List of trusted constants names
*
* @var array
*/
public $trusted_constants = [];
/**
* This is an array of trusted static classes.
* If empty access to all static classes is allowed.
* If set to 'none' none is allowed.
*
* @var array
*/
public $static_classes = [];
/**
* This is an nested array of trusted classes and static methods.
* If empty access to all static classes and methods is allowed.
* Format:
* array (
* 'class_1' => array('method_1', 'method_2'), // allowed methods listed
* 'class_2' => array(), // all methods of class allowed
* )
* If set to null none is allowed.
*
* @var array
*/
public $trusted_static_methods = [];
/**
* This is an array of trusted static properties.
* If empty access to all static classes and properties is allowed.
* Format:
* array (
* 'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
* 'class_2' => array(), // all properties of class allowed
* )
* If set to null none is allowed.
*
* @var array
*/
public $trusted_static_properties = [];
/**
* This is an array of trusted PHP functions.
* If empty all functions are allowed.
* To disable all PHP functions set $php_functions = null.
*
* @var array
*/
public $php_functions = ['isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',];
/**
* This is an array of trusted PHP modifiers.
* If empty all modifiers are allowed.
* To disable all modifier set $php_modifiers = null.
*
* @var array
*/
public $php_modifiers = ['escape', 'count', 'sizeof', 'nl2br',];
/**
* This is an array of allowed tags.
* If empty no restriction by allowed_tags.
*
* @var array
*/
public $allowed_tags = [];
/**
* This is an array of disabled tags.
* If empty no restriction by disabled_tags.
*
* @var array
*/
public $disabled_tags = [];
/**
* This is an array of allowed modifier plugins.
* If empty no restriction by allowed_modifiers.
*
* @var array
*/
public $allowed_modifiers = [];
/**
* This is an array of disabled modifier plugins.
* If empty no restriction by disabled_modifiers.
*
* @var array
*/
public $disabled_modifiers = [];
/**
* This is an array of disabled special $smarty variables.
*
* @var array
*/
public $disabled_special_smarty_vars = [];
/**
* This is an array of trusted streams.
* If empty all streams are allowed.
* To disable all streams set $streams = null.
*
* @var array
*/
public $streams = ['file'];
/**
* + flag if constants can be accessed from template
*
* @var boolean
*/
public $allow_constants = true;
/**
* + flag if super globals can be accessed from template
*
* @var boolean
*/
public $allow_super_globals = true;
/**
* max template nesting level
*
* @var int
*/
public $max_template_nesting = 0;
/**
* current template nesting level
*
* @var int
*/
private $_current_template_nesting = 0;
/**
* Cache for $resource_dir lookup
*
* @var array
*/
protected $_resource_dir = [];
/**
* Cache for $template_dir lookup
*
* @var array
*/
protected $_template_dir = [];
/**
* Cache for $config_dir lookup
*
* @var array
*/
protected $_config_dir = [];
/**
* Cache for $secure_dir lookup
*
* @var array
*/
protected $_secure_dir = [];
/**
* Cache for $php_resource_dir lookup
*
* @var array
*/
protected $_php_resource_dir = null;
/**
* Cache for $trusted_dir lookup
*
* @var array
*/
protected $_trusted_dir = null;
/**
* Cache for include path status
*
* @var bool
*/
protected $_include_path_status = false;
/**
* Cache for $_include_array lookup
*
* @var array
*/
protected $_include_dir = [];
/**
* @param Smarty $smarty
*/
public function __construct(Smarty $smarty) {
$this->smarty = $smarty;
}
/**
* Check if PHP function is trusted.
*
* @param string $function_name
* @param object $compiler compiler object
*
* @return boolean true if function is trusted
*/
public function isTrustedPhpFunction($function_name, $compiler) {
if (isset($this->php_functions)
&& (empty($this->php_functions) || in_array($function_name, $this->php_functions))
) {
return true;
}
$compiler->trigger_template_error("PHP function '{$function_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if static class is trusted.
*
* @param string $class_name
* @param object $compiler compiler object
*
* @return boolean true if class is trusted
*/
public function isTrustedStaticClass($class_name, $compiler) {
if (isset($this->static_classes)
&& (empty($this->static_classes) || in_array($class_name, $this->static_classes))
) {
return true;
}
$compiler->trigger_template_error("access to static class '{$class_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if static class method/property is trusted.
*
* @param string $class_name
* @param string $params
* @param object $compiler compiler object
*
* @return boolean true if class method is trusted
*/
public function isTrustedStaticClassAccess($class_name, $params, $compiler) {
if (!isset($params[2])) {
// fall back
return $this->isTrustedStaticClass($class_name, $compiler);
}
if ($params[2] === 'method') {
$allowed = $this->trusted_static_methods;
$name = substr($params[0], 0, strpos($params[0], '('));
} else {
$allowed = $this->trusted_static_properties;
// strip '$'
$name = substr($params[0], 1);
}
if (isset($allowed)) {
if (empty($allowed)) {
// fall back
return $this->isTrustedStaticClass($class_name, $compiler);
}
if (isset($allowed[$class_name])
&& (empty($allowed[$class_name]) || in_array($name, $allowed[$class_name]))
) {
return true;
}
}
$compiler->trigger_template_error("access to static class '{$class_name}' {$params[2]} '{$name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if PHP modifier is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
*
* @return boolean true if modifier is trusted
* @deprecated
*/
public function isTrustedPhpModifier($modifier_name, $compiler) {
if (isset($this->php_modifiers)
&& (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))
) {
return true;
}
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if tag is trusted.
*
* @param string $tag_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedTag($tag_name, $compiler) {
// check for internal always required tags
if (in_array(
$tag_name,
[
'assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin',
'private_object_block_function', 'private_object_function', 'private_registered_function',
'private_registered_block', 'private_special_variable', 'private_print_expression',
'private_modifier',
]
)
) {
return true;
}
// check security settings
if (empty($this->allowed_tags)) {
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
}
} elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if special $smarty variable is trusted.
*
* @param string $var_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedSpecialSmartyVar($var_name, $compiler) {
if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
return true;
} else {
$compiler->trigger_template_error(
"special variable '\$smarty.{$var_name}' not allowed by security setting",
null,
true
);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if modifier plugin is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedModifier($modifier_name, $compiler) {
// check for internal always allowed modifier
if (in_array($modifier_name, ['default'])) {
return true;
}
// check security settings
if (empty($this->allowed_modifiers)) {
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
return true;
} else {
$compiler->trigger_template_error(
"modifier '{$modifier_name}' disabled by security setting",
null,
true
);
}
} elseif (in_array($modifier_name, $this->allowed_modifiers)
&& !in_array($modifier_name, $this->disabled_modifiers)
) {
return true;
} else {
$compiler->trigger_template_error(
"modifier '{$modifier_name}' not allowed by security setting",
null,
true
);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if constants are enabled or trusted
*
* @param string $const constant name
* @param object $compiler compiler object
*
* @return bool
*/
public function isTrustedConstant($const, $compiler) {
if (in_array($const, ['true', 'false', 'null'])) {
return true;
}
if (!empty($this->trusted_constants)) {
if (!in_array(strtolower($const), $this->trusted_constants)) {
$compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
return false;
}
return true;
}
if ($this->allow_constants) {
return true;
}
$compiler->trigger_template_error("Security: access to constants not permitted");
return false;
}
/**
* Check if stream is trusted.
*
* @param string $stream_name
*
* @return boolean true if stream is trusted
* @throws Exception if stream is not trusted
*/
public function isTrustedStream($stream_name) {
if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) {
return true;
}
throw new Exception("stream '{$stream_name}' not allowed by security setting");
}
/**
* Check if directory of file resource is trusted.
*
* @param string $filepath
* @param null|bool $isConfig
*
* @return bool true if directory is trusted
* @throws \Smarty\Exception if directory is not trusted
*/
public function isTrustedResourceDir($filepath, $isConfig = null) {
if ($this->_include_path_status !== $this->smarty->use_include_path) {
$_dir =
$this->smarty->use_include_path ? $this->smarty->getIncludePathDirs() : [];
if ($this->_include_dir !== $_dir) {
$this->_updateResourceDir($this->_include_dir, $_dir);
$this->_include_dir = $_dir;
}
$this->_include_path_status = $this->smarty->use_include_path;
}
$_dir = $this->smarty->getTemplateDir();
if ($this->_template_dir !== $_dir) {
$this->_updateResourceDir($this->_template_dir, $_dir);
$this->_template_dir = $_dir;
}
$_dir = $this->smarty->getConfigDir();
if ($this->_config_dir !== $_dir) {
$this->_updateResourceDir($this->_config_dir, $_dir);
$this->_config_dir = $_dir;
}
if ($this->_secure_dir !== $this->secure_dir) {
$this->secure_dir = (array)$this->secure_dir;
foreach ($this->secure_dir as $k => $d) {
$this->secure_dir[$k] = $this->smarty->_realpath($d . DIRECTORY_SEPARATOR, true);
}
$this->_updateResourceDir($this->_secure_dir, $this->secure_dir);
$this->_secure_dir = $this->secure_dir;
}
$addPath = $this->_checkDir($filepath, $this->_resource_dir);
if ($addPath !== false) {
$this->_resource_dir = array_merge($this->_resource_dir, $addPath);
}
return true;
}
/**
* Check if URI (e.g. {fetch} or {html_image}) is trusted
* To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}".
* So "http://username:password@hello.world.example.org:8080/some-path?some=query-string"
* is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}.
*
* @param string $uri
*
* @return boolean true if URI is trusted
* @throws Exception if URI is not trusted
* @uses $trusted_uri for list of patterns to match against $uri
*/
public function isTrustedUri($uri) {
$_uri = parse_url($uri);
if (!empty($_uri['scheme']) && !empty($_uri['host'])) {
$_uri = $_uri['scheme'] . '://' . $_uri['host'];
foreach ($this->trusted_uri as $pattern) {
if (preg_match($pattern, $_uri)) {
return true;
}
}
}
throw new Exception("URI '{$uri}' not allowed by security setting");
}
/**
* Remove old directories and its sub folders, add new directories
*
* @param array $oldDir
* @param array $newDir
*/
private function _updateResourceDir($oldDir, $newDir) {
foreach ($oldDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$length = strlen($directory);
foreach ($this->_resource_dir as $dir) {
if (substr($dir, 0, $length) === $directory) {
unset($this->_resource_dir[$dir]);
}
}
}
foreach ($newDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$this->_resource_dir[$directory] = true;
}
}
/**
* Check if file is inside a valid directory
*
* @param string $filepath
* @param array $dirs valid directories
*
* @return array|bool
* @throws \Smarty\Exception
*/
private function _checkDir($filepath, $dirs) {
$directory = dirname($this->smarty->_realpath($filepath, true)) . DIRECTORY_SEPARATOR;
$_directory = [];
if (!preg_match('#[\\\\/][.][.][\\\\/]#', $directory)) {
while (true) {
// test if the directory is trusted
if (isset($dirs[$directory])) {
return $_directory;
}
// abort if we've reached root
if (!preg_match('#[\\\\/][^\\\\/]+[\\\\/]$#', $directory)) {
// give up
break;
}
// remember the directory to add it to _resource_dir in case we're successful
$_directory[$directory] = true;
// bubble up one level
$directory = preg_replace('#[\\\\/][^\\\\/]+[\\\\/]$#', DIRECTORY_SEPARATOR, $directory);
}
}
// give up
throw new Exception(sprintf('Smarty Security: not trusted file path \'%s\' ', $filepath));
}
/**
* Loads security class and enables security
*
* @param \Smarty $smarty
* @param string|Security $security_class if a string is used, it must be class-name
*
* @return \Smarty current Smarty instance for chaining
* @throws \Smarty\Exception when an invalid class name is provided
*/
public static function enableSecurity(Smarty $smarty, $security_class) {
if ($security_class instanceof Security) {
$smarty->security_policy = $security_class;
return $smarty;
} elseif (is_object($security_class)) {
throw new Exception("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
}
if ($security_class === null) {
$security_class = $smarty->security_class;
}
if (!class_exists($security_class)) {
throw new Exception("Security class '$security_class' is not defined");
} elseif ($security_class !== Security::class && !is_subclass_of($security_class, Security::class)) {
throw new Exception("Class '$security_class' must extend " . Security::class . ".");
} else {
$smarty->security_policy = new $security_class($smarty);
}
return $smarty;
}
/**
* Start template processing
*
* @param $template
*
* @throws Exception
*/
public function startTemplate($template) {
if ($this->max_template_nesting > 0 && $this->_current_template_nesting++ >= $this->max_template_nesting) {
throw new Exception("maximum template nesting level of '{$this->max_template_nesting}' exceeded when calling '{$template->template_resource}'");
}
}
/**
* Exit template processing
*/
public function endTemplate() {
if ($this->max_template_nesting > 0) {
$this->_current_template_nesting--;
}
}
/**
* Register callback functions call at start/end of template rendering
*
* @param \Smarty\Template $template
*/
public function registerCallBacks(Template $template) {
$template->startRenderCallbacks[] = [$this, 'startTemplate'];
$template->endRenderCallbacks[] = [$this, 'endTemplate'];
}
}

View File

@@ -274,14 +274,14 @@ class Smarty extends \Smarty\TemplateBase
* This should be instance of \Smarty_Security. * This should be instance of \Smarty_Security.
* *
* @var string * @var string
* @see \Smarty_Security * @see \Smarty\Security
*/ */
public $security_class = \Smarty_Security::class; public $security_class = \Smarty\Security::class;
/** /**
* implementation of security class * implementation of security class
* *
* @var \Smarty_Security * @var \Smarty\Security
*/ */
public $security_policy = null; public $security_policy = null;
@@ -592,7 +592,7 @@ class Smarty extends \Smarty\TemplateBase
* @param string $resource_name template name * @param string $resource_name template name
* *
* @return bool status * @return bool status
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function templateExists($resource_name) public function templateExists($resource_name)
{ {
@@ -604,14 +604,14 @@ class Smarty extends \Smarty\TemplateBase
/** /**
* Loads security class and enables security * Loads security class and enables security
* *
* @param string|\Smarty_Security $security_class if a string is used, it must be class-name * @param string|\Smarty\Security $security_class if a string is used, it must be class-name
* *
* @return Smarty current Smarty instance for chaining * @return Smarty current Smarty instance for chaining
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function enableSecurity($security_class = null) public function enableSecurity($security_class = null)
{ {
\Smarty_Security::enableSecurity($this, $security_class); \Smarty\Security::enableSecurity($this, $security_class);
return $this; return $this;
} }
@@ -845,7 +845,7 @@ class Smarty extends \Smarty\TemplateBase
* @param boolean $do_clone flag is Smarty object shall be cloned * @param boolean $do_clone flag is Smarty object shall be cloned
* *
* @return \Smarty\Template template object * @return \Smarty\Template template object
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
{ {
@@ -909,7 +909,7 @@ class Smarty extends \Smarty\TemplateBase
* @param \Smarty\Template $template * @param \Smarty\Template $template
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function _getTemplateId( public function _getTemplateId(
$template_name, $template_name,
@@ -1224,9 +1224,6 @@ class Smarty extends \Smarty\TemplateBase
/** /**
* Empty cache for a specific template * Empty cache for a specific template
* *
* @api Smarty::clearCache()
* @link https://www.smarty.net/docs/en/api.clear.cache.tpl
*
* @param string $template_name template name * @param string $template_name template name
* @param string $cache_id cache id * @param string $cache_id cache id
* @param string $compile_id compile id * @param string $compile_id compile id
@@ -1234,7 +1231,10 @@ class Smarty extends \Smarty\TemplateBase
* @param string $type resource type * @param string $type resource type
* *
* @return int number of cache files deleted * @return int number of cache files deleted
* @throws \SmartyException * @throws \Smarty\Exception
*@link https://www.smarty.net/docs/en/api.clear.cache.tpl
*
* @api Smarty::clearCache()
*/ */
public function clearCache( public function clearCache(
$template_name, $template_name,
@@ -1271,15 +1271,15 @@ class Smarty extends \Smarty\TemplateBase
/** /**
* Delete compiled template file * Delete compiled template file
* *
* @api Smarty::clearCompiledTemplate()
* @link https://www.smarty.net/docs/en/api.clear.compiled.template.tpl
*
* @param string $resource_name template name * @param string $resource_name template name
* @param string $compile_id compile id * @param string $compile_id compile id
* @param integer $exp_time expiration time * @param integer $exp_time expiration time
* *
* @return int number of template files deleted * @return int number of template files deleted
* @throws \SmartyException * @throws \Smarty\Exception
*@link https://www.smarty.net/docs/en/api.clear.compiled.template.tpl
*
* @api Smarty::clearCompiledTemplate()
*/ */
public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
{ {
@@ -1511,7 +1511,7 @@ class Smarty extends \Smarty\TemplateBase
* @param string $content * @param string $content
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function cacheModifiedCheck(Template\Cached $cached, \Smarty\Template $_template, $content) public function cacheModifiedCheck(Template\Cached $cached, \Smarty\Template $_template, $content)
{ {
@@ -1572,7 +1572,7 @@ class Smarty extends \Smarty\TemplateBase
* @param Template $template template object * @param Template $template template object
* *
* @return string the filtered content * @return string the filtered content
*@throws SmartyException *@throws Exception
*/ */
public function runFilter($type, $content, Template $template) public function runFilter($type, $content, Template $template)
{ {
@@ -1748,8 +1748,8 @@ class Smarty extends \Smarty\TemplateBase
* @param string $_filepath complete filepath * @param string $_filepath complete filepath
* @param string $_contents file content * @param string $_contents file content
* *
* @throws SmartyException
* @return boolean true * @return boolean true
*@throws Exception
*/ */
public function writeFile($_filepath, $_contents) public function writeFile($_filepath, $_contents)
{ {
@@ -1768,7 +1768,7 @@ class Smarty extends \Smarty\TemplateBase
clearstatcache(); clearstatcache();
if (++$i === 3) { if (++$i === 3) {
error_reporting($_error_reporting); error_reporting($_error_reporting);
throw new SmartyException("unable to create directory {$_dirpath}"); throw new Exception("unable to create directory {$_dirpath}");
} }
sleep(1); sleep(1);
} }
@@ -1777,7 +1777,7 @@ class Smarty extends \Smarty\TemplateBase
$_tmp_file = $_dirpath . DIRECTORY_SEPARATOR . str_replace(array('.', ','), '_', uniqid('wrt', true)); $_tmp_file = $_dirpath . DIRECTORY_SEPARATOR . str_replace(array('.', ','), '_', uniqid('wrt', true));
if (!file_put_contents($_tmp_file, $_contents)) { if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting); error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_tmp_file}"); throw new Exception("unable to write file {$_tmp_file}");
} }
/* /*
* Windows' rename() fails if the destination exists, * Windows' rename() fails if the destination exists,
@@ -1807,7 +1807,7 @@ class Smarty extends \Smarty\TemplateBase
} }
if (!$success) { if (!$success) {
error_reporting($_error_reporting); error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_filepath}"); throw new Exception("unable to write file {$_filepath}");
} }
// set file permissions // set file permissions
@chmod($_filepath, 0666 & ~umask()); @chmod($_filepath, 0666 & ~umask());
@@ -1844,7 +1844,7 @@ class Smarty extends \Smarty\TemplateBase
return $this->runtimes[$type] = new Smarty\Runtime\TplFunctionRuntime(); return $this->runtimes[$type] = new Smarty\Runtime\TplFunctionRuntime();
} }
throw new \SmartyException('Trying to load invalid runtime ' . $type); throw new \Smarty\Exception('Trying to load invalid runtime ' . $type);
} }
/** /**
@@ -1858,7 +1858,7 @@ class Smarty extends \Smarty\TemplateBase
try { try {
$this->getRuntime($type); $this->getRuntime($type);
return true; return true;
} catch (\SmartyException $e) { } catch (\Smarty\Exception $e) {
return false; return false;
} }
} }

View File

@@ -16,7 +16,7 @@ use Smarty\Template\Source;
use Smarty\Template\Cached; use Smarty\Template\Cached;
use Smarty\Template\Compiled; use Smarty\Template\Compiled;
use Smarty\Template\Config; use Smarty\Template\Config;
use SmartyException; use Smarty\Exception;
/** /**
* Main class with template data structures and methods * Main class with template data structures and methods
@@ -143,7 +143,7 @@ class Template extends TemplateBase {
* seconds * seconds
* @param bool $_isConfig * @param bool $_isConfig
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct( public function __construct(
$template_resource, $template_resource,
@@ -182,7 +182,7 @@ class Template extends TemplateBase {
* *
* @return string * @return string
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function render($no_output_filter = true, $display = null) { public function render($no_output_filter = true, $display = null) {
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
@@ -193,7 +193,7 @@ class Template extends TemplateBase {
} }
// checks if template exists // checks if template exists
if (!$this->source->exists) { if (!$this->source->exists) {
throw new SmartyException( throw new Exception(
"Unable to load template '{$this->source->type}:{$this->source->name}'" . "Unable to load template '{$this->source->type}:{$this->source->name}'" .
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '') ($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
); );
@@ -273,7 +273,7 @@ class Template extends TemplateBase {
* @param string $content_func function name * @param string $content_func function name
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function _subTemplateRender( public function _subTemplateRender(
$template, $template,
@@ -444,7 +444,7 @@ class Template extends TemplateBase {
* @param bool $cache flag if called from cache file * @param bool $cache flag if called from cache file
* *
* @return bool flag if compiled or cache file is valid * @return bool flag if compiled or cache file is valid
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function _decodeProperties(Template $tpl, $properties, $cache = false) { public function _decodeProperties(Template $tpl, $properties, $cache = false) {
// on cache resources other than file check version stored in cache code // on cache resources other than file check version stored in cache code
@@ -543,7 +543,7 @@ class Template extends TemplateBase {
* Get unique template id * Get unique template id
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function _getTemplateId() { public function _getTemplateId() {
return $this->templateId ?? $this->templateId = return $this->templateId ?? $this->templateId =
@@ -553,10 +553,10 @@ class Template extends TemplateBase {
/** /**
* runtime error not matching capture tags * runtime error not matching capture tags
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function capture_error() { public function capture_error() {
throw new SmartyException("Not matching {capture} open/close in '{$this->template_resource}'"); throw new Exception("Not matching {capture} open/close in '{$this->template_resource}'");
} }
/** /**
@@ -602,7 +602,7 @@ class Template extends TemplateBase {
/** /**
* Load compiler object * Load compiler object
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function loadCompiler() { public function loadCompiler() {
$this->compiler = $this->compiler =
@@ -650,7 +650,7 @@ class Template extends TemplateBase {
* @param string $property_name property name * @param string $property_name property name
* *
* @return mixed|Cached * @return mixed|Cached
* @throws SmartyException * @throws Exception
*/ */
public function __get($property_name) { public function __get($property_name) {
switch ($property_name) { switch ($property_name) {
@@ -669,7 +669,7 @@ class Template extends TemplateBase {
return $this->smarty->$property_name; return $this->smarty->$property_name;
} }
} }
throw new SmartyException("template property '$property_name' does not exist."); throw new Exception("template property '$property_name' does not exist.");
} }
/** /**
@@ -678,7 +678,7 @@ class Template extends TemplateBase {
* @param string $property_name property name * @param string $property_name property name
* @param mixed $value value * @param mixed $value value
* *
* @throws SmartyException * @throws Exception
*/ */
public function __set($property_name, $value) { public function __set($property_name, $value) {
switch ($property_name) { switch ($property_name) {
@@ -694,7 +694,7 @@ class Template extends TemplateBase {
return; return;
} }
} }
throw new SmartyException("invalid template property '$property_name'."); throw new Exception("invalid template property '$property_name'.");
} }
/** /**
@@ -790,7 +790,7 @@ class Template extends TemplateBase {
* configuration * configuration
* *
* @return bool * @return bool
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function mustCompile() { public function mustCompile() {
if (!$this->source->exists) { if (!$this->source->exists) {
@@ -799,7 +799,7 @@ class Template extends TemplateBase {
} else { } else {
$parent_resource = ''; $parent_resource = '';
} }
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); throw new Exception("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
} }
if ($this->mustCompile === null) { if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->handler->uncompiled && $this->mustCompile = (!$this->source->handler->uncompiled &&

View File

@@ -84,7 +84,7 @@ class Cached extends ResourceBase {
* *
* @param Template $_template template object * @param Template $_template template object
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function __construct(Template $_template) { public function __construct(Template $_template) {
$this->compile_id = $_template->compile_id; $this->compile_id = $_template->compile_id;
@@ -282,7 +282,7 @@ class Cached extends ResourceBase {
* @param Template $_template * @param Template $_template
* @param bool $no_output_filter * @param bool $no_output_filter
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function updateCache(Template $_template, $no_output_filter) { public function updateCache(Template $_template, $no_output_filter) {
ob_start(); ob_start();
@@ -315,7 +315,7 @@ class Cached extends ResourceBase {
* @param Template $_template * @param Template $_template
* @param bool $no_output_filter * @param bool $no_output_filter
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function removeNoCacheHash(Template $_template, $no_output_filter) { private function removeNoCacheHash(Template $_template, $no_output_filter) {
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/'; $php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';

View File

@@ -88,13 +88,13 @@ class Compiled extends ResourceBase {
* @param Template $_template * @param Template $_template
* *
* @return string * @return string
* @throws Exception * @throws \Smarty\Exception
*/ */
public function render(Template $_template) { public function render(Template $_template) {
// checks if template exists // checks if template exists
if (!$_template->source->exists) { if (!$_template->source->exists) {
$type = $_template->source->isConfig ? 'config' : 'template'; $type = $_template->source->isConfig ? 'config' : 'template';
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'"); throw new \Smarty\Exception("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
} }
if ($_template->smarty->debugging) { if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) { if (!isset($_template->smarty->_debug)) {
@@ -200,7 +200,7 @@ class Compiled extends ResourceBase {
* @param string $code compiled code * @param string $code compiled code
* *
* @return bool success * @return bool success
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function write(Template $_template, $code) { public function write(Template $_template, $code) {
if (!$_template->source->handler->recompiled) { if (!$_template->source->handler->recompiled) {

View File

@@ -4,7 +4,7 @@ namespace Smarty\Template;
use Smarty; use Smarty;
use Smarty\Template; use Smarty\Template;
use SmartyException; use Smarty\Exception;
/** /**
* Smarty Config Resource Data Object * Smarty Config Resource Data Object
@@ -65,7 +65,7 @@ class Config extends Source {
* @param string $template_resource resource identifier * @param string $template_resource resource identifier
* *
* @return Config Source Object * @return Config Source Object
* @throws SmartyException * @throws Exception
*/ */
public static function load( public static function load(
Template $_template = null, Template $_template = null,
@@ -78,13 +78,13 @@ class Config extends Source {
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
} }
if (empty($template_resource)) { if (empty($template_resource)) {
throw new SmartyException('Source: Missing name'); throw new Exception('Source: Missing name');
} }
// parse resource_name, load resource handler // parse resource_name, load resource handler
[$name, $type] = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type); [$name, $type] = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle // make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[$type])) { if (isset($_incompatible_resources[$type])) {
throw new SmartyException("Unable to use resource '{$type}' for config"); throw new Exception("Unable to use resource '{$type}' for config");
} }
$source = new Config($smarty, $template_resource, $type, $name); $source = new Config($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template); $source->handler->populate($source, $_template);

View File

@@ -116,7 +116,7 @@ abstract class ResourceBase {
$unifunc = $this->unifunc; $unifunc = $this->unifunc;
} }
if (empty($unifunc) || !function_exists($unifunc)) { if (empty($unifunc) || !function_exists($unifunc)) {
throw new \SmartyException("Invalid compiled template for '{$_template->template_resource}'"); throw new \Smarty\Exception("Invalid compiled template for '{$_template->template_resource}'");
} }
if ($_template->startRenderCallbacks) { if ($_template->startRenderCallbacks) {
foreach ($_template->startRenderCallbacks as $callback) { foreach ($_template->startRenderCallbacks as $callback) {

View File

@@ -4,7 +4,7 @@ namespace Smarty\Template;
use Smarty; use Smarty;
use Smarty\Template; use Smarty\Template;
use SmartyException; use Smarty\Exception;
/** /**
* Smarty Resource Data Object * Smarty Resource Data Object
@@ -136,7 +136,7 @@ class Source {
* @param string $type type of resource * @param string $type type of resource
* @param string $name resource name * @param string $name resource name
* *
* @throws \SmartyException * @throws \Smarty\Exception
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with * @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
*/ */
public function __construct(Smarty $smarty, $resource, $type, $name) { public function __construct(Smarty $smarty, $resource, $type, $name) {
@@ -157,7 +157,7 @@ class Source {
* @param string $template_resource resource identifier * @param string $template_resource resource identifier
* *
* @return Source Source Object * @return Source Source Object
* @throws SmartyException * @throws Exception
*/ */
public static function load( public static function load(
Template $_template = null, Template $_template = null,
@@ -169,7 +169,7 @@ class Source {
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
} }
if (empty($template_resource)) { if (empty($template_resource)) {
throw new SmartyException('Source: Missing name'); throw new Exception('Source: Missing name');
} }
// parse resource_name, load resource handler, identify unique resource name // parse resource_name, load resource handler, identify unique resource name
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) { if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
@@ -207,7 +207,7 @@ class Source {
* Get source content * Get source content
* *
* @return string * @return string
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function getContent() { public function getContent() {
return isset($this->content) ? $this->content : $this->handler->getContent($this); return isset($this->content) ? $this->content : $this->handler->getContent($this);
@@ -216,7 +216,7 @@ class Source {
/** /**
* get default content from template or config resource handler * get default content from template or config resource handler
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function _getDefaultTemplate($default_handler) { public function _getDefaultTemplate($default_handler) {
$_content = $_timestamp = null; $_content = $_timestamp = null;
@@ -229,7 +229,7 @@ class Source {
if ($this->exists) { if ($this->exists) {
$this->timestamp = filemtime($_return); $this->timestamp = filemtime($_return);
} else { } else {
throw new SmartyException( throw new Exception(
'Default handler: Unable to load ' . 'Default handler: Unable to load ' .
($this->isConfig ? 'config' : 'template') . ($this->isConfig ? 'config' : 'template') .
" default file '{$_return}' for '{$this->type}:{$this->name}'" " default file '{$_return}' for '{$this->type}:{$this->name}'"
@@ -244,7 +244,7 @@ class Source {
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval'); $this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
} else { } else {
$this->exists = false; $this->exists = false;
throw new SmartyException( throw new Exception(
'Default handler: No ' . ($this->isConfig ? 'config' : 'template') . 'Default handler: No ' . ($this->isConfig ? 'config' : 'template') .
" default content for '{$this->type}:{$this->name}'" " default content for '{$this->type}:{$this->name}'"
); );

View File

@@ -14,8 +14,8 @@ use Smarty\Cacheresource\Base;
use Smarty\Data; use Smarty\Data;
use Smarty\Smarty; use Smarty\Smarty;
use Smarty\Template; use Smarty\Template;
use Smarty_Data; use Smarty\DataObject;
use SmartyException; use Smarty\Exception;
/** /**
* Class with shared smarty/template methods * Class with shared smarty/template methods
@@ -92,7 +92,7 @@ abstract class TemplateBase extends Data {
* @param object $parent next higher level of Smarty variables * @param object $parent next higher level of Smarty variables
* *
* @return string rendered template output * @return string rendered template output
* @throws SmartyException * @throws Exception
* @throws Exception * @throws Exception
*/ */
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) { public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) {
@@ -109,7 +109,7 @@ abstract class TemplateBase extends Data {
* @param object $parent next higher level of Smarty variables * @param object $parent next higher level of Smarty variables
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) { public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {
// display template // display template
@@ -127,7 +127,7 @@ abstract class TemplateBase extends Data {
* *
* @return bool cache status * @return bool cache status
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.is.cached.tpl * @link https://www.smarty.net/docs/en/api.is.cached.tpl
* *
* @api Smarty::isCached() * @api Smarty::isCached()
@@ -147,21 +147,21 @@ abstract class TemplateBase extends Data {
* *
* @return mixed * @return mixed
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function _execute($template, $cache_id, $compile_id, $parent, $function) { private function _execute($template, $cache_id, $compile_id, $parent, $function) {
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
$saveVars = true; $saveVars = true;
if ($template === null) { if ($template === null) {
if (!$this->_isTplObj()) { if (!$this->_isTplObj()) {
throw new SmartyException($function . '():Missing \'$template\' parameter'); throw new Exception($function . '():Missing \'$template\' parameter');
} else { } else {
$template = $this; $template = $this;
} }
} elseif (is_object($template)) { } elseif (is_object($template)) {
/* @var Template $template */ /* @var Template $template */
if (!isset($template->_objType) || !$template->_isTplObj()) { if (!isset($template->_objType) || !$template->_isTplObj()) {
throw new SmartyException($function . '():Template object expected'); throw new Exception($function . '():Template object expected');
} }
} else { } else {
// get template object // get template object
@@ -262,7 +262,7 @@ abstract class TemplateBase extends Data {
* @param mixed $cache_attr caching attributes if any * @param mixed $cache_attr caching attributes if any
* *
* @return \Smarty|\Smarty\Template * @return \Smarty|\Smarty\Template
* @throws \SmartyException * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl * @link https://www.smarty.net/docs/en/api.register.plugin.tpl
* *
* @api Smarty::registerPlugin() * @api Smarty::registerPlugin()
@@ -270,11 +270,11 @@ abstract class TemplateBase extends Data {
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) { public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) {
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
if (isset($smarty->registered_plugins[$type][$name])) { if (isset($smarty->registered_plugins[$type][$name])) {
throw new SmartyException("Plugin tag '{$name}' already registered"); throw new Exception("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) { } elseif (!is_callable($callback)) {
throw new SmartyException("Plugin '{$name}' not callable"); throw new Exception("Plugin '{$name}' not callable");
} elseif ($cacheable && $cache_attr) { } elseif ($cacheable && $cache_attr) {
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable."); throw new Exception("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
} else { } else {
$smarty->registered_plugins[$type][$name] = [$callback, (bool)$cacheable, (array)$cache_attr]; $smarty->registered_plugins[$type][$name] = [$callback, (bool)$cacheable, (array)$cache_attr];
} }
@@ -307,7 +307,7 @@ abstract class TemplateBase extends Data {
* @param string $name filter name * @param string $name filter name
* *
* @return bool * @return bool
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::loadFilter() * @api Smarty::loadFilter()
* @link https://www.smarty.net/docs/en/api.load.filter.tpl * @link https://www.smarty.net/docs/en/api.load.filter.tpl
* *
@@ -328,7 +328,7 @@ abstract class TemplateBase extends Data {
$smarty->registered_filters[$type][$_filter_name] = $_plugin; $smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true; return true;
} }
throw new SmartyException("{$type}filter '{$name}' not found or callable"); throw new Exception("{$type}filter '{$name}' not found or callable");
} }
/** /**
@@ -338,7 +338,7 @@ abstract class TemplateBase extends Data {
* @param string $name filter name * @param string $name filter name
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::unloadFilter() * @api Smarty::unloadFilter()
* *
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl * @link https://www.smarty.net/docs/en/api.unload.filter.tpl
@@ -367,7 +367,7 @@ abstract class TemplateBase extends Data {
* @param string|null $name optional filter name * @param string|null $name optional filter name
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.filter.tpl * @link https://www.smarty.net/docs/en/api.register.filter.tpl
* *
* @api Smarty::registerFilter() * @api Smarty::registerFilter()
@@ -377,7 +377,7 @@ abstract class TemplateBase extends Data {
$this->_checkFilterType($type); $this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback); $name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) { if (!is_callable($callback)) {
throw new SmartyException("{$type}filter '{$name}' not callable"); throw new Exception("{$type}filter '{$name}' not callable");
} }
$smarty->registered_filters[$type][$name] = $callback; $smarty->registered_filters[$type][$name] = $callback;
return $this; return $this;
@@ -390,7 +390,7 @@ abstract class TemplateBase extends Data {
* @param callback|string $callback * @param callback|string $callback
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::unregisterFilter() * @api Smarty::unregisterFilter()
* *
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl * @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
@@ -421,7 +421,7 @@ abstract class TemplateBase extends Data {
* @param array $block_methods list of block-methods * @param array $block_methods list of block-methods
* *
* @return \Smarty|\Smarty\Template * @return \Smarty|\Smarty\Template
* @throws \SmartyException * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.object.tpl * @link https://www.smarty.net/docs/en/api.register.object.tpl
* *
* @api Smarty::registerObject() * @api Smarty::registerObject()
@@ -438,7 +438,7 @@ abstract class TemplateBase extends Data {
if (!empty($allowed_methods_properties)) { if (!empty($allowed_methods_properties)) {
foreach ((array)$allowed_methods_properties as $method) { foreach ((array)$allowed_methods_properties as $method) {
if (!is_callable([$object, $method]) && !property_exists($object, $method)) { if (!is_callable([$object, $method]) && !property_exists($object, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object"); throw new Exception("Undefined method or property '$method' in registered object");
} }
} }
} }
@@ -446,7 +446,7 @@ abstract class TemplateBase extends Data {
if (!empty($block_methods)) { if (!empty($block_methods)) {
foreach ((array)$block_methods as $method) { foreach ((array)$block_methods as $method) {
if (!is_callable([$object, $method])) { if (!is_callable([$object, $method])) {
throw new SmartyException("Undefined method '$method' in registered object"); throw new Exception("Undefined method '$method' in registered object");
} }
} }
} }
@@ -536,8 +536,8 @@ abstract class TemplateBase extends Data {
* variables * variables
* @param null $name optional data block name * @param null $name optional data block name
* *
* @return Smarty_Data data object * @return DataObject data object
* @throws SmartyException * @throws Exception
* @api Smarty::createData() * @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl * @link https://www.smarty.net/docs/en/api.create.data.tpl
* *
@@ -545,7 +545,7 @@ abstract class TemplateBase extends Data {
public function createData(Data $parent = null, $name = null) { public function createData(Data $parent = null, $name = null) {
/* @var Smarty $smarty */ /* @var Smarty $smarty */
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
$dataObj = new Smarty_Data($parent, $smarty, $name); $dataObj = new DataObject($parent, $smarty, $name);
if ($smarty->debugging) { if ($smarty->debugging) {
\Smarty\Debug::register_data($dataObj); \Smarty\Debug::register_data($dataObj);
} }
@@ -582,7 +582,7 @@ abstract class TemplateBase extends Data {
* @param string $object_name object name * @param string $object_name object name
* *
* @return object * @return object
* @throws \SmartyException if no such object is found * @throws \Smarty\Exception if no such object is found
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl * @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
* *
* @api Smarty::getRegisteredObject() * @api Smarty::getRegisteredObject()
@@ -590,10 +590,10 @@ abstract class TemplateBase extends Data {
public function getRegisteredObject($object_name) { public function getRegisteredObject($object_name) {
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
if (!isset($smarty->registered_objects[$object_name])) { if (!isset($smarty->registered_objects[$object_name])) {
throw new SmartyException("'$object_name' is not a registered object"); throw new Exception("'$object_name' is not a registered object");
} }
if (!is_object($smarty->registered_objects[$object_name][0])) { if (!is_object($smarty->registered_objects[$object_name][0])) {
throw new SmartyException("registered '$object_name' is not an object"); throw new Exception("registered '$object_name' is not an object");
} }
return $smarty->registered_objects[$object_name][0]; return $smarty->registered_objects[$object_name][0];
} }
@@ -617,7 +617,7 @@ abstract class TemplateBase extends Data {
* to addto add * to addto add
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::addLiterals() * @api Smarty::addLiterals()
* *
*/ */
@@ -635,7 +635,7 @@ abstract class TemplateBase extends Data {
* to setto set * to setto set
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::setLiterals() * @api Smarty::setLiterals()
* *
*/ */
@@ -655,14 +655,14 @@ abstract class TemplateBase extends Data {
* @param Smarty $smarty * @param Smarty $smarty
* @param array $literals * @param array $literals
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function _setLiterals(Smarty $smarty, $literals) { private function _setLiterals(Smarty $smarty, $literals) {
$literals = array_combine($literals, $literals); $literals = array_combine($literals, $literals);
$error = isset($literals[$smarty->left_delimiter]) ? [$smarty->left_delimiter] : []; $error = isset($literals[$smarty->left_delimiter]) ? [$smarty->left_delimiter] : [];
$error = isset($literals[$smarty->right_delimiter]) ? $error[] = $smarty->right_delimiter : $error; $error = isset($literals[$smarty->right_delimiter]) ? $error[] = $smarty->right_delimiter : $error;
if (!empty($error)) { if (!empty($error)) {
throw new SmartyException( throw new Exception(
'User defined literal(s) "' . $error . 'User defined literal(s) "' . $error .
'" may not be identical with left or right delimiter' '" may not be identical with left or right delimiter'
); );
@@ -675,11 +675,11 @@ abstract class TemplateBase extends Data {
* *
* @param string $type * @param string $type
* *
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
private function _checkFilterType($type) { private function _checkFilterType($type) {
if (!isset($this->filterTypes[$type])) { if (!isset($this->filterTypes[$type])) {
throw new SmartyException("Illegal filter type '{$type}'"); throw new Exception("Illegal filter type '{$type}'");
} }
} }
@@ -709,7 +709,7 @@ abstract class TemplateBase extends Data {
* register * register
* *
* @return TemplateBase * @return TemplateBase
* @throws \SmartyException * @throws \Smarty\Exception
* @api Smarty::registerClass() * @api Smarty::registerClass()
* @link https://www.smarty.net/docs/en/api.register.class.tpl * @link https://www.smarty.net/docs/en/api.register.class.tpl
* *
@@ -718,7 +718,7 @@ abstract class TemplateBase extends Data {
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
// test if exists // test if exists
if (!class_exists($class_impl)) { if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class"); throw new Exception("Undefined class '$class_impl' in register template class");
} }
// register the class // register the class
$smarty->registered_classes[$class_name] = $class_impl; $smarty->registered_classes[$class_name] = $class_impl;
@@ -766,7 +766,7 @@ abstract class TemplateBase extends Data {
* @param callable $callback class/method name * @param callable $callback class/method name
* *
* @return TemplateBase * @return TemplateBase
* @throws SmartyException if $callback is not callable * @throws Exception if $callback is not callable
* @api Smarty::registerDefaultConfigHandler() * @api Smarty::registerDefaultConfigHandler()
* *
*/ */
@@ -775,7 +775,7 @@ abstract class TemplateBase extends Data {
if (is_callable($callback)) { if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback; $smarty->default_config_handler_func = $callback;
} else { } else {
throw new SmartyException('Default config handler not callable'); throw new Exception('Default config handler not callable');
} }
return $this; return $this;
} }
@@ -786,7 +786,7 @@ abstract class TemplateBase extends Data {
* @param callable $callback class/method name * @param callable $callback class/method name
* *
* @return TemplateBase * @return TemplateBase
* @throws SmartyException if $callback is not callable * @throws Exception if $callback is not callable
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl * @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
* *
* @api Smarty::registerDefaultPluginHandler() * @api Smarty::registerDefaultPluginHandler()
@@ -796,7 +796,7 @@ abstract class TemplateBase extends Data {
if (is_callable($callback)) { if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback; $smarty->default_plugin_handler_func = $callback;
} else { } else {
throw new SmartyException("Default plugin handler '$callback' not callable"); throw new Exception("Default plugin handler '$callback' not callable");
} }
return $this; return $this;
} }
@@ -807,7 +807,7 @@ abstract class TemplateBase extends Data {
* @param callable $callback class/method name * @param callable $callback class/method name
* *
* @return TemplateBase * @return TemplateBase
* @throws SmartyException if $callback is not callable * @throws Exception if $callback is not callable
* @api Smarty::registerDefaultTemplateHandler() * @api Smarty::registerDefaultTemplateHandler()
* *
*/ */
@@ -816,7 +816,7 @@ abstract class TemplateBase extends Data {
if (is_callable($callback)) { if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback; $smarty->default_template_handler_func = $callback;
} else { } else {
throw new SmartyException('Default template handler not callable'); throw new Exception('Default template handler not callable');
} }
return $this; return $this;
} }
@@ -862,14 +862,14 @@ abstract class TemplateBase extends Data {
* @param string $tpl_name * @param string $tpl_name
* *
* @return TemplateBase * @return TemplateBase
* @throws SmartyException if file is not readable * @throws Exception if file is not readable
* @api Smarty::setDebugTemplate() * @api Smarty::setDebugTemplate()
* *
*/ */
public function setDebugTemplate($tpl_name) { public function setDebugTemplate($tpl_name) {
$smarty = $this->_getSmartyObj(); $smarty = $this->_getSmartyObj();
if (!is_readable($tpl_name)) { if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'"); throw new Exception("Unknown file '{$tpl_name}'");
} }
$smarty->debug_tpl = $tpl_name; $smarty->debug_tpl = $tpl_name;
return $this; return $this;

33
src/UndefinedVariable.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace Smarty;
/**
* class for undefined variable object
* This class defines an object for undefined variable handling
*
* @package Smarty
* @subpackage Template
*/
class UndefinedVariable extends Variable {
/**
* Returns null for not existing properties
*
* @param string $name
*
* @return null
*/
public function __get($name) {
return null;
}
/**
* Always returns an empty string.
*
* @return string
*/
public function __toString() {
return '';
}
}

View File

@@ -1,70 +0,0 @@
<?php
/**
* Smarty Plugin Data
* This file contains the data object
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for the Smarty data object
* The Smarty data object will hold Smarty variables in the current scope
*
* @package Smarty
* @subpackage Template
*/
class Smarty_Data extends \Smarty\Data
{
/**
* Counter
*
* @var int
*/
public static $count = 0;
/**
* Data block name
*
* @var string
*/
public $dataObjectName = '';
/**
* Smarty object
*
* @var Smarty
*/
public $smarty = null;
/**
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty|Template $smarty global smarty instance
* @param string $name optional data block name
*
* @throws SmartyException
*/
public function __construct($_parent = null, $smarty = null, $name = null)
{
parent::__construct();
self::$count++;
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
$this->smarty = $smarty;
if (is_object($_parent)) {
// when object set up back pointer
$this->parent = $_parent;
} elseif (is_array($_parent)) {
// set up variable values
foreach ($_parent as $_key => $_val) {
$this->tpl_vars[ $_key ] = new \Smarty\Variable($_val);
}
} elseif ($_parent !== null) {
throw new SmartyException('Wrong type for template variables');
}
}
}

View File

@@ -1,682 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage Security
* @author Uwe Tews
*/
/**
* FIXME: Smarty_Security API
* - getter and setter instead of public properties would allow cultivating an internal cache properly
* - current implementation of isTrustedResourceDir() assumes that Smarty::$template_dir and Smarty::$config_dir
* are immutable the cache is killed every time either of the variables change. That means that two distinct
* Smarty objects with differing
* $template_dir or $config_dir should NOT share the same Smarty_Security instance,
* as this would lead to (severe) performance penalty! how should this be handled?
*/
use Smarty\Template;
/**
* This class does contain the security settings
*/
#[\AllowDynamicProperties]
class Smarty_Security
{
/**
* This is the list of template directories that are considered secure.
* $template_dir is in this list implicitly.
*
* @var array
*/
public $secure_dir = array();
/**
* This is an array of directories where trusted php scripts reside.
* {@link $security} is disabled during their inclusion/execution.
*
* @var array
*/
public $trusted_dir = array();
/**
* List of regular expressions (PCRE) that include trusted URIs
*
* @var array
*/
public $trusted_uri = array();
/**
* List of trusted constants names
*
* @var array
*/
public $trusted_constants = array();
/**
* This is an array of trusted static classes.
* If empty access to all static classes is allowed.
* If set to 'none' none is allowed.
*
* @var array
*/
public $static_classes = array();
/**
* This is an nested array of trusted classes and static methods.
* If empty access to all static classes and methods is allowed.
* Format:
* array (
* 'class_1' => array('method_1', 'method_2'), // allowed methods listed
* 'class_2' => array(), // all methods of class allowed
* )
* If set to null none is allowed.
*
* @var array
*/
public $trusted_static_methods = array();
/**
* This is an array of trusted static properties.
* If empty access to all static classes and properties is allowed.
* Format:
* array (
* 'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
* 'class_2' => array(), // all properties of class allowed
* )
* If set to null none is allowed.
*
* @var array
*/
public $trusted_static_properties = array();
/**
* This is an array of trusted PHP functions.
* If empty all functions are allowed.
* To disable all PHP functions set $php_functions = null.
*
* @var array
*/
public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',);
/**
* This is an array of trusted PHP modifiers.
* If empty all modifiers are allowed.
* To disable all modifier set $php_modifiers = null.
*
* @var array
*/
public $php_modifiers = array('escape', 'count', 'sizeof', 'nl2br',);
/**
* This is an array of allowed tags.
* If empty no restriction by allowed_tags.
*
* @var array
*/
public $allowed_tags = array();
/**
* This is an array of disabled tags.
* If empty no restriction by disabled_tags.
*
* @var array
*/
public $disabled_tags = array();
/**
* This is an array of allowed modifier plugins.
* If empty no restriction by allowed_modifiers.
*
* @var array
*/
public $allowed_modifiers = array();
/**
* This is an array of disabled modifier plugins.
* If empty no restriction by disabled_modifiers.
*
* @var array
*/
public $disabled_modifiers = array();
/**
* This is an array of disabled special $smarty variables.
*
* @var array
*/
public $disabled_special_smarty_vars = array();
/**
* This is an array of trusted streams.
* If empty all streams are allowed.
* To disable all streams set $streams = null.
*
* @var array
*/
public $streams = array('file');
/**
* + flag if constants can be accessed from template
*
* @var boolean
*/
public $allow_constants = true;
/**
* + flag if super globals can be accessed from template
*
* @var boolean
*/
public $allow_super_globals = true;
/**
* max template nesting level
*
* @var int
*/
public $max_template_nesting = 0;
/**
* current template nesting level
*
* @var int
*/
private $_current_template_nesting = 0;
/**
* Cache for $resource_dir lookup
*
* @var array
*/
protected $_resource_dir = array();
/**
* Cache for $template_dir lookup
*
* @var array
*/
protected $_template_dir = array();
/**
* Cache for $config_dir lookup
*
* @var array
*/
protected $_config_dir = array();
/**
* Cache for $secure_dir lookup
*
* @var array
*/
protected $_secure_dir = array();
/**
* Cache for $php_resource_dir lookup
*
* @var array
*/
protected $_php_resource_dir = null;
/**
* Cache for $trusted_dir lookup
*
* @var array
*/
protected $_trusted_dir = null;
/**
* Cache for include path status
*
* @var bool
*/
protected $_include_path_status = false;
/**
* Cache for $_include_array lookup
*
* @var array
*/
protected $_include_dir = array();
/**
* @param Smarty $smarty
*/
public function __construct($smarty)
{
$this->smarty = $smarty;
}
/**
* Check if PHP function is trusted.
*
* @param string $function_name
* @param object $compiler compiler object
*
* @return boolean true if function is trusted
*/
public function isTrustedPhpFunction($function_name, $compiler)
{
if (isset($this->php_functions)
&& (empty($this->php_functions) || in_array($function_name, $this->php_functions))
) {
return true;
}
$compiler->trigger_template_error("PHP function '{$function_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if static class is trusted.
*
* @param string $class_name
* @param object $compiler compiler object
*
* @return boolean true if class is trusted
*/
public function isTrustedStaticClass($class_name, $compiler)
{
if (isset($this->static_classes)
&& (empty($this->static_classes) || in_array($class_name, $this->static_classes))
) {
return true;
}
$compiler->trigger_template_error("access to static class '{$class_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if static class method/property is trusted.
*
* @param string $class_name
* @param string $params
* @param object $compiler compiler object
*
* @return boolean true if class method is trusted
*/
public function isTrustedStaticClassAccess($class_name, $params, $compiler)
{
if (!isset($params[ 2 ])) {
// fall back
return $this->isTrustedStaticClass($class_name, $compiler);
}
if ($params[ 2 ] === 'method') {
$allowed = $this->trusted_static_methods;
$name = substr($params[ 0 ], 0, strpos($params[ 0 ], '('));
} else {
$allowed = $this->trusted_static_properties;
// strip '$'
$name = substr($params[ 0 ], 1);
}
if (isset($allowed)) {
if (empty($allowed)) {
// fall back
return $this->isTrustedStaticClass($class_name, $compiler);
}
if (isset($allowed[ $class_name ])
&& (empty($allowed[ $class_name ]) || in_array($name, $allowed[ $class_name ]))
) {
return true;
}
}
$compiler->trigger_template_error("access to static class '{$class_name}' {$params[2]} '{$name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if PHP modifier is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
* @deprecated
* @return boolean true if modifier is trusted
*/
public function isTrustedPhpModifier($modifier_name, $compiler)
{
if (isset($this->php_modifiers)
&& (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))
) {
return true;
}
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting");
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if tag is trusted.
*
* @param string $tag_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedTag($tag_name, $compiler)
{
// check for internal always required tags
if (in_array(
$tag_name,
array(
'assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin',
'private_object_block_function', 'private_object_function', 'private_registered_function',
'private_registered_block', 'private_special_variable', 'private_print_expression',
'private_modifier'
)
)
) {
return true;
}
// check security settings
if (empty($this->allowed_tags)) {
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
}
} elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if special $smarty variable is trusted.
*
* @param string $var_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedSpecialSmartyVar($var_name, $compiler)
{
if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
return true;
} else {
$compiler->trigger_template_error(
"special variable '\$smarty.{$var_name}' not allowed by security setting",
null,
true
);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if modifier plugin is trusted.
*
* @param string $modifier_name
* @param object $compiler compiler object
*
* @return boolean true if tag is trusted
*/
public function isTrustedModifier($modifier_name, $compiler)
{
// check for internal always allowed modifier
if (in_array($modifier_name, array('default'))) {
return true;
}
// check security settings
if (empty($this->allowed_modifiers)) {
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
return true;
} else {
$compiler->trigger_template_error(
"modifier '{$modifier_name}' disabled by security setting",
null,
true
);
}
} elseif (in_array($modifier_name, $this->allowed_modifiers)
&& !in_array($modifier_name, $this->disabled_modifiers)
) {
return true;
} else {
$compiler->trigger_template_error(
"modifier '{$modifier_name}' not allowed by security setting",
null,
true
);
}
return false; // should not, but who knows what happens to the compiler in the future?
}
/**
* Check if constants are enabled or trusted
*
* @param string $const constant name
* @param object $compiler compiler object
*
* @return bool
*/
public function isTrustedConstant($const, $compiler)
{
if (in_array($const, array('true', 'false', 'null'))) {
return true;
}
if (!empty($this->trusted_constants)) {
if (!in_array(strtolower($const), $this->trusted_constants)) {
$compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
return false;
}
return true;
}
if ($this->allow_constants) {
return true;
}
$compiler->trigger_template_error("Security: access to constants not permitted");
return false;
}
/**
* Check if stream is trusted.
*
* @param string $stream_name
*
* @return boolean true if stream is trusted
* @throws SmartyException if stream is not trusted
*/
public function isTrustedStream($stream_name)
{
if (isset($this->streams) && (empty($this->streams) || in_array($stream_name, $this->streams))) {
return true;
}
throw new SmartyException("stream '{$stream_name}' not allowed by security setting");
}
/**
* Check if directory of file resource is trusted.
*
* @param string $filepath
* @param null|bool $isConfig
*
* @return bool true if directory is trusted
* @throws \SmartyException if directory is not trusted
*/
public function isTrustedResourceDir($filepath, $isConfig = null)
{
if ($this->_include_path_status !== $this->smarty->use_include_path) {
$_dir =
$this->smarty->use_include_path ? $this->smarty->getIncludePathDirs() : array();
if ($this->_include_dir !== $_dir) {
$this->_updateResourceDir($this->_include_dir, $_dir);
$this->_include_dir = $_dir;
}
$this->_include_path_status = $this->smarty->use_include_path;
}
$_dir = $this->smarty->getTemplateDir();
if ($this->_template_dir !== $_dir) {
$this->_updateResourceDir($this->_template_dir, $_dir);
$this->_template_dir = $_dir;
}
$_dir = $this->smarty->getConfigDir();
if ($this->_config_dir !== $_dir) {
$this->_updateResourceDir($this->_config_dir, $_dir);
$this->_config_dir = $_dir;
}
if ($this->_secure_dir !== $this->secure_dir) {
$this->secure_dir = (array)$this->secure_dir;
foreach ($this->secure_dir as $k => $d) {
$this->secure_dir[ $k ] = $this->smarty->_realpath($d . DIRECTORY_SEPARATOR, true);
}
$this->_updateResourceDir($this->_secure_dir, $this->secure_dir);
$this->_secure_dir = $this->secure_dir;
}
$addPath = $this->_checkDir($filepath, $this->_resource_dir);
if ($addPath !== false) {
$this->_resource_dir = array_merge($this->_resource_dir, $addPath);
}
return true;
}
/**
* Check if URI (e.g. {fetch} or {html_image}) is trusted
* To simplify things, isTrustedUri() resolves all input to "{$PROTOCOL}://{$HOSTNAME}".
* So "http://username:password@hello.world.example.org:8080/some-path?some=query-string"
* is reduced to "http://hello.world.example.org" prior to applying the patters from {@link $trusted_uri}.
*
* @param string $uri
*
* @return boolean true if URI is trusted
* @throws SmartyException if URI is not trusted
* @uses $trusted_uri for list of patterns to match against $uri
*/
public function isTrustedUri($uri)
{
$_uri = parse_url($uri);
if (!empty($_uri[ 'scheme' ]) && !empty($_uri[ 'host' ])) {
$_uri = $_uri[ 'scheme' ] . '://' . $_uri[ 'host' ];
foreach ($this->trusted_uri as $pattern) {
if (preg_match($pattern, $_uri)) {
return true;
}
}
}
throw new SmartyException("URI '{$uri}' not allowed by security setting");
}
/**
* Remove old directories and its sub folders, add new directories
*
* @param array $oldDir
* @param array $newDir
*/
private function _updateResourceDir($oldDir, $newDir)
{
foreach ($oldDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$length = strlen($directory);
foreach ($this->_resource_dir as $dir) {
if (substr($dir, 0, $length) === $directory) {
unset($this->_resource_dir[ $dir ]);
}
}
}
foreach ($newDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$this->_resource_dir[ $directory ] = true;
}
}
/**
* Check if file is inside a valid directory
*
* @param string $filepath
* @param array $dirs valid directories
*
* @return array|bool
* @throws \SmartyException
*/
private function _checkDir($filepath, $dirs)
{
$directory = dirname($this->smarty->_realpath($filepath, true)) . DIRECTORY_SEPARATOR;
$_directory = array();
if (!preg_match('#[\\\\/][.][.][\\\\/]#', $directory)) {
while (true) {
// test if the directory is trusted
if (isset($dirs[ $directory ])) {
return $_directory;
}
// abort if we've reached root
if (!preg_match('#[\\\\/][^\\\\/]+[\\\\/]$#', $directory)) {
// give up
break;
}
// remember the directory to add it to _resource_dir in case we're successful
$_directory[ $directory ] = true;
// bubble up one level
$directory = preg_replace('#[\\\\/][^\\\\/]+[\\\\/]$#', DIRECTORY_SEPARATOR, $directory);
}
}
// give up
throw new SmartyException(sprintf('Smarty Security: not trusted file path \'%s\' ', $filepath));
}
/**
* Loads security class and enables security
*
* @param \Smarty $smarty
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return \Smarty current Smarty instance for chaining
* @throws \SmartyException when an invalid class name is provided
*/
public static function enableSecurity(Smarty $smarty, $security_class)
{
if ($security_class instanceof Smarty_Security) {
$smarty->security_policy = $security_class;
return $smarty;
} elseif (is_object($security_class)) {
throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
}
if ($security_class === null) {
$security_class = $smarty->security_class;
}
if (!class_exists($security_class)) {
throw new SmartyException("Security class '$security_class' is not defined");
} elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
} else {
$smarty->security_policy = new $security_class($smarty);
}
return $smarty;
}
/**
* Start template processing
*
* @param $template
*
* @throws SmartyException
*/
public function startTemplate($template)
{
if ($this->max_template_nesting > 0 && $this->_current_template_nesting++ >= $this->max_template_nesting) {
throw new SmartyException("maximum template nesting level of '{$this->max_template_nesting}' exceeded when calling '{$template->template_resource}'");
}
}
/**
* Exit template processing
*/
public function endTemplate()
{
if ($this->max_template_nesting > 0) {
$this->_current_template_nesting--;
}
}
/**
* Register callback functions call at start/end of template rendering
*
* @param \Smarty\Template $template
*/
public function registerCallBacks(Template $template)
{
$template->startRenderCallbacks[] = array($this, 'startTemplate');
$template->endRenderCallbacks[] = array($this, 'endTemplate');
}
}

View File

@@ -1,33 +0,0 @@
<?php
/**
* class for undefined variable object
* This class defines an object for undefined variable handling
*
* @package Smarty
* @subpackage Template
*/
class Smarty_Undefined_Variable extends \Smarty\Variable
{
/**
* Returns null for not existing properties
*
* @param string $name
*
* @return null
*/
public function __get($name)
{
return null;
}
/**
* Always returns an empty string.
*
* @return string
*/
public function __toString()
{
return '';
}
}

View File

@@ -1,73 +0,0 @@
<?php
/**
* Smarty compiler exception class
*
* @package Smarty
*/
class SmartyCompilerException extends SmartyException
{
/**
* The constructor of the exception
*
* @param string $message The Exception message to throw.
* @param int $code The Exception code.
* @param string|null $filename The filename where the exception is thrown.
* @param int|null $line The line number where the exception is thrown.
* @param Throwable|null $previous The previous exception used for the exception chaining.
*/
public function __construct(
string $message = "",
int $code = 0,
?string $filename = null,
?int $line = null,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
// These are optional parameters, should be be overridden only when present!
if ($filename) {
$this->file = $filename;
}
if ($line) {
$this->line = $line;
}
}
/**
* @return string
*/
public function __toString()
{
return ' --> Smarty Compiler: ' . $this->message . ' <-- ';
}
/**
* @param int $line
*/
public function setLine($line)
{
$this->line = $line;
}
/**
* The template source snippet relating to the error
*
* @type string|null
*/
public $source = null;
/**
* The raw text of the error message
*
* @type string|null
*/
public $desc = null;
/**
* The resource identifier or template name
*
* @type string|null
*/
public $template = null;
}

View File

@@ -1,19 +0,0 @@
<?php
/**
* Smarty exception class
*
* @package Smarty
*/
class SmartyException extends Exception
{
public static $escape = false;
/**
* @return string
*/
public function __toString()
{
return ' --> Smarty: ' . (self::$escape ? htmlentities($this->message) : $this->message) . ' <-- ';
}
}

View File

@@ -4,6 +4,7 @@
* *
*/ */
use Smarty\Exception;
use Smarty\TemplateBase; use Smarty\TemplateBase;
use Smarty\Template; use Smarty\Template;
@@ -166,7 +167,7 @@ class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD); PHPUnit_Smarty::$pdo = new PDO(DB_DSN, DB_USER, DB_PASSWD);
} }
catch (PDOException $e) { catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$timezone = date_default_timezone_get(); $timezone = date_default_timezone_get();
$j = PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';"); $j = PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';");

View File

@@ -1,5 +1,6 @@
<?php <?php
use Smarty\Exception;
use Smarty\Template\Cached; use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php'; require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php';
@@ -12,7 +13,7 @@ class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
try { try {
$this->db = PHPUnit_Smarty::$pdo; $this->db = PHPUnit_Smarty::$pdo;
} catch (PDOException $e) { } catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id'); $this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id'); $this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');

View File

@@ -32,7 +32,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
*/ */
public function testUnknownConfigFile() public function testUnknownConfigFile()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to load config \'file:foo.conf\''); $this->expectExceptionMessage('Unable to load config \'file:foo.conf\'');
$this->smarty->configLoad('foo.conf'); $this->smarty->configLoad('foo.conf');
} }
@@ -42,7 +42,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
*/ */
public function testRegisterUnknownDefaultConfigHandler() public function testRegisterUnknownDefaultConfigHandler()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Default config handler'); $this->expectExceptionMessage('Default config handler');
$this->expectExceptionMessage('not callable'); $this->expectExceptionMessage('not callable');
$this->smarty->registerDefaultConfigHandler('foo'); $this->smarty->registerDefaultConfigHandler('foo');
@@ -52,7 +52,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
* test default config handler replacement (config data) * test default config handler replacement (config data)
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function testDefaultConfigHandlerReplacement() public function testDefaultConfigHandlerReplacement()
{ {
@@ -65,7 +65,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
* test default config handler replacement (other config file) * test default config handler replacement (other config file)
* *
* @throws \Exception * @throws \Exception
* @throws \SmartyException * @throws \Smarty\Exception
*/ */
public function testDefaultConfigHandlerReplacementByConfigFile() public function testDefaultConfigHandlerReplacementByConfigFile()
{ {
@@ -76,7 +76,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
public function testDefaultConfigHandlerReplacementByConfigFileFail() public function testDefaultConfigHandlerReplacementByConfigFileFail()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage("Unable to load config default file 'no.conf' for 'file:fo.conf'"); $this->expectExceptionMessage("Unable to load config default file 'no.conf' for 'file:fo.conf'");
$this->smarty->registerDefaultConfigHandler('configHandlerFile'); $this->smarty->registerDefaultConfigHandler('configHandlerFile');
$this->smarty->configLoad('fo.conf'); $this->smarty->configLoad('fo.conf');
@@ -88,7 +88,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
*/ */
public function testDefaultConfigHandlerReplacementReturningFalse() public function testDefaultConfigHandlerReplacementReturningFalse()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to load config \'file:foo.conf\''); $this->expectExceptionMessage('Unable to load config \'file:foo.conf\'');
$this->smarty->configLoad('foo.conf'); $this->smarty->configLoad('foo.conf');
} }
@@ -98,7 +98,7 @@ class DefaultConfigHandlerTest extends PHPUnit_Smarty
*/ */
public function testDefaultConfigHandlerReplacementReturningFalse1() public function testDefaultConfigHandlerReplacementReturningFalse1()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('No config default content for \'file:bla.conf\''); $this->expectExceptionMessage('No config default content for \'file:bla.conf\'');
$this->smarty->registerDefaultConfigHandler('configHandlerData'); $this->smarty->registerDefaultConfigHandler('configHandlerData');
$this->smarty->configLoad('bla.conf'); $this->smarty->configLoad('bla.conf');

View File

@@ -1,4 +1,7 @@
<?php <?php
use Smarty\Exception;
require_once SMARTY_DIR . '../demo/plugins/resource.mysqls.php'; require_once SMARTY_DIR . '../demo/plugins/resource.mysqls.php';
class Smarty_Resource_Mysqlstest extends _MysqlsPlugin class Smarty_Resource_Mysqlstest extends _MysqlsPlugin
@@ -10,7 +13,7 @@ class Smarty_Resource_Mysqlstest extends _MysqlsPlugin
} }
catch catch
(PDOException $e) { (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
} }

View File

@@ -1,4 +1,7 @@
<?php <?php
use Smarty\Exception;
require_once SMARTY_DIR . '../demo/plugins/resource.mysql.php'; require_once SMARTY_DIR . '../demo/plugins/resource.mysql.php';
class Smarty_Resource_Mysqltest extends _MysqlPlugin class Smarty_Resource_Mysqltest extends _MysqlPlugin
@@ -10,7 +13,7 @@ class Smarty_Resource_Mysqltest extends _MysqlPlugin
} }
catch catch
(PDOException $e) { (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new Exception('Mysql Resource failed: ' . $e->getMessage());
} }
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name'); $this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name'); $this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');

View File

@@ -143,7 +143,7 @@ if (MysqlResourceEnable == true) {
* *
*/ */
public function testUnknownTemplate() { public function testUnknownTemplate() {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to load template \'mysqlstest:foo.tpl\''); $this->expectExceptionMessage('Unable to load template \'mysqlstest:foo.tpl\'');
$this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl')); $this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl'));
} }

View File

@@ -6,6 +6,8 @@
* @author Uwe Tews * @author Uwe Tews
*/ */
use Smarty\Exception;
/** /**
* class for file resource tests * class for file resource tests
* *
@@ -69,7 +71,7 @@ class FileResourceTest extends PHPUnit_Smarty
*/ */
public function testTemplateFileNotExists3() public function testTemplateFileNotExists3()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to'); $this->expectExceptionMessage('Unable to');
$this->expectExceptionMessage('notthere.tpl'); $this->expectExceptionMessage('notthere.tpl');
$this->smarty->fetch('notthere.tpl'); $this->smarty->fetch('notthere.tpl');
@@ -222,7 +224,7 @@ class FileResourceTest extends PHPUnit_Smarty
*/ */
public function testRelativeIncludeFail() public function testRelativeIncludeFail()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('Unable to'); $this->expectExceptionMessage('Unable to');
$this->smarty->fetch('relative_sub.tpl'); $this->smarty->fetch('relative_sub.tpl');
} }
@@ -234,7 +236,7 @@ class FileResourceTest extends PHPUnit_Smarty
*/ */
public function testRelativeIncludeFailOtherDir() public function testRelativeIncludeFailOtherDir()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('./hello.tpl'); $this->expectExceptionMessage('./hello.tpl');
$this->smarty->addTemplateDir('./templates_2'); $this->smarty->addTemplateDir('./templates_2');
$this->smarty->fetch('relative_notexist.tpl'); $this->smarty->fetch('relative_notexist.tpl');
@@ -331,7 +333,7 @@ class FileResourceTest extends PHPUnit_Smarty
return; return;
} }
catch (SmartyException $e) { catch (Exception $e) {
// this was expected to fail // this was expected to fail
} }
} else { } else {

View File

@@ -146,7 +146,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testTemplateStramNotExists3() public function testTemplateStramNotExists3()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('\'global:notthere\''); $this->expectExceptionMessage('\'global:notthere\'');
$this->smarty->fetch('global:notthere'); $this->smarty->fetch('global:notthere');
} }

View File

@@ -6,6 +6,8 @@
* @author Uwe Tews * @author Uwe Tews
*/ */
use Smarty\CompilerException;
/** /**
* class for security test * class for security test
* *
@@ -27,18 +29,6 @@ class SecurityTest extends PHPUnit_Smarty
$this->cleanDirs(); $this->cleanDirs();
} }
/**
* test that security is loaded
' *'/
public function testSecurityReenable()
{
$this->smarty->disableSecurity();
$this->smarty->enableSecurity('Security');
$this->smarty->fetch('helloworld.tpl');
$this->smarty->disableSecurity();
$this->smarty->enableSecurity('Security');
$this->smarty->fetch('helloworld.tpl');
}
/** /**
* test that security is loaded * test that security is loaded
*/ */
@@ -62,7 +52,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedPHPFunction() public function testNotTrustedPHPFunction()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('PHP function \'sizeof\' not allowed by security setting'); $this->expectExceptionMessage('PHP function \'sizeof\' not allowed by security setting');
$this->smarty->security_policy->php_functions = array('null'); $this->smarty->security_policy->php_functions = array('null');
$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'); $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}');
@@ -95,7 +85,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedModifier() public function testNotTrustedModifier()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('modifier \'sizeof\' not allowed by security setting'); $this->expectExceptionMessage('modifier \'sizeof\' not allowed by security setting');
$this->smarty->security_policy->php_modifiers = array('null'); $this->smarty->security_policy->php_modifiers = array('null');
@$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}'); @$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}');
@@ -128,7 +118,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotAllowedTags2() public function testNotAllowedTags2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('tag \'cycle\' not allowed by security setting'); $this->expectExceptionMessage('tag \'cycle\' not allowed by security setting');
$this->smarty->security_policy->allowed_tags = array('counter'); $this->smarty->security_policy->allowed_tags = array('counter');
$this->smarty->fetch('string:{counter}{cycle values="1,2"}'); $this->smarty->fetch('string:{counter}{cycle values="1,2"}');
@@ -141,7 +131,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testDisabledTags() public function testDisabledTags()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('tag \'cycle\' disabled by security setting'); $this->expectExceptionMessage('tag \'cycle\' disabled by security setting');
$this->smarty->security_policy->disabled_tags = array('cycle'); $this->smarty->security_policy->disabled_tags = array('cycle');
$this->smarty->fetch('string:{counter}{cycle values="1,2"}'); $this->smarty->fetch('string:{counter}{cycle values="1,2"}');
@@ -171,7 +161,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotAllowedModifier() public function testNotAllowedModifier()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('modifier \'lower\' not allowed by security setting'); $this->expectExceptionMessage('modifier \'lower\' not allowed by security setting');
$this->smarty->security_policy->allowed_modifiers = array('upper'); $this->smarty->security_policy->allowed_modifiers = array('upper');
$this->smarty->fetch('string:{"hello"|upper}{"world"|lower}'); $this->smarty->fetch('string:{"hello"|upper}{"world"|lower}');
@@ -184,7 +174,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testDisabledModifier() public function testDisabledModifier()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('modifier \'lower\' disabled by security setting'); $this->expectExceptionMessage('modifier \'lower\' disabled by security setting');
$this->smarty->security_policy->disabled_modifiers = array('lower'); $this->smarty->security_policy->disabled_modifiers = array('lower');
$this->smarty->fetch('string:{"hello"|upper}{"world"|lower}'); $this->smarty->fetch('string:{"hello"|upper}{"world"|lower}');
@@ -235,7 +225,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedDirectory() public function testNotTrustedDirectory()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('not trusted file path'); $this->expectExceptionMessage('not trusted file path');
$this->smarty->security_policy->secure_dir = array(str_replace('\\', '/', __DIR__ . '/templates_3/')); $this->smarty->security_policy->secure_dir = array(str_replace('\\', '/', __DIR__ . '/templates_3/'));
$this->smarty->fetch('string:{include file="templates_2/hello.tpl"}'); $this->smarty->fetch('string:{include file="templates_2/hello.tpl"}');
@@ -267,7 +257,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedStaticClass() public function testNotTrustedStaticClass()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting'); $this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
$this->smarty->security_policy->static_classes = array('null'); $this->smarty->security_policy->static_classes = array('null');
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}'); $this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
@@ -278,7 +268,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedStaticClassEval() public function testNotTrustedStaticClassEval()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('dynamic static class not allowed by security setting'); $this->expectExceptionMessage('dynamic static class not allowed by security setting');
$this->smarty->security_policy->static_classes = array('null'); $this->smarty->security_policy->static_classes = array('null');
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}'); $this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
@@ -289,7 +279,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedStaticClassSmartyVar() public function testNotTrustedStaticClassSmartyVar()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('dynamic static class not allowed by security setting'); $this->expectExceptionMessage('dynamic static class not allowed by security setting');
$this->smarty->security_policy->static_classes = array('null'); $this->smarty->security_policy->static_classes = array('null');
$this->smarty->fetch('string:{$smarty.template_object::square(5)}'); $this->smarty->fetch('string:{$smarty.template_object::square(5)}');
@@ -332,7 +322,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testTemplateNotTrustedStream() public function testTemplateNotTrustedStream()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('stream \'global\' not allowed by security setting'); $this->expectExceptionMessage('stream \'global\' not allowed by security setting');
stream_wrapper_register("global", "ResourceStreamSecurity") stream_wrapper_register("global", "ResourceStreamSecurity")
or die("Failed to register protocol"); or die("Failed to register protocol");
@@ -361,7 +351,7 @@ class SecurityTest extends PHPUnit_Smarty
*/ */
public function testNotTrustedUri() public function testNotTrustedUri()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('URI \'https://www.smarty.net/docs/en/preface.tpl\' not allowed by security setting'); $this->expectExceptionMessage('URI \'https://www.smarty.net/docs/en/preface.tpl\' not allowed by security setting');
$this->smarty->security_policy->trusted_uri = array(); $this->smarty->security_policy->trusted_uri = array();
$this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}')); $this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
@@ -371,7 +361,7 @@ class SecurityTest extends PHPUnit_Smarty
* In security mode, accessing $smarty.template_object should be illegal. * In security mode, accessing $smarty.template_object should be illegal.
*/ */
public function testSmartyTemplateObject() { public function testSmartyTemplateObject() {
$this->expectException(SmartyCompilerException::class); $this->expectException(CompilerException::class);
$this->smarty->display('string:{$smarty.template_object}'); $this->smarty->display('string:{$smarty.template_object}');
} }
@@ -387,10 +377,7 @@ class mysecuritystaticclass
return $i * $i; return $i * $i;
} }
} }
class Security extends Smarty_Security
{
}
#[AllowDynamicProperties] #[AllowDynamicProperties]
class ResourceStreamSecurity class ResourceStreamSecurity
{ {

View File

@@ -50,7 +50,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginUnknown() public function testBlockPluginUnknown()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('unknown tag \'bar\''); $this->expectExceptionMessage('unknown tag \'bar\'');
$this->assertEquals("hello world", $this->smarty->fetch('unknown.tpl')); $this->assertEquals("hello world", $this->smarty->fetch('unknown.tpl'));
} }
@@ -76,7 +76,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginRegisteredFunction2() public function testBlockPluginRegisteredFunction2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('block tag \'blockplugintest\' not callable'); $this->expectExceptionMessage('block tag \'blockplugintest\' not callable');
$this->assertEquals('block test', $this->smarty->fetch('registered.tpl')); $this->assertEquals('block test', $this->smarty->fetch('registered.tpl'));
} }
@@ -103,7 +103,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginRegisteredStatic2() public function testBlockPluginRegisteredStatic2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('block tag \'blockpluginstatic\' not callable'); $this->expectExceptionMessage('block tag \'blockpluginstatic\' not callable');
$this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl')); $this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl'));
} }
@@ -130,7 +130,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginRegisteredMethod2() public function testBlockPluginRegisteredMethod2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('block tag \'blockpluginmethod\' not callable'); $this->expectExceptionMessage('block tag \'blockpluginmethod\' not callable');
$this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl')); $this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl'));
} }
@@ -157,7 +157,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
*/ */
public function testBlockPluginRegisteredObject2() public function testBlockPluginRegisteredObject2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('block tag \'myobject\' not callable'); $this->expectExceptionMessage('block tag \'myobject\' not callable');
$this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl')); $this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl'));
} }

View File

@@ -759,7 +759,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockChildOutsideBlock_025() public function testSmartyBlockChildOutsideBlock_025()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('\'{$smarty.block.child}\' used outside {block} tags'); $this->expectExceptionMessage('\'{$smarty.block.child}\' used outside {block} tags');
$this->smarty->fetch('025_parent.tpl'); $this->smarty->fetch('025_parent.tpl');
} }
@@ -769,7 +769,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockParentOutsideBlock_026() public function testSmartyBlockParentOutsideBlock_026()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('\'{$smarty.block.parent}\' used outside {block} tags'); $this->expectExceptionMessage('\'{$smarty.block.parent}\' used outside {block} tags');
$this->smarty->fetch('026_child.tpl'); $this->smarty->fetch('026_child.tpl');
} }
@@ -779,7 +779,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockParentInParent_027() public function testSmartyBlockParentInParent_027()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('illegal \'{$smarty.block.parent}\''); $this->expectExceptionMessage('illegal \'{$smarty.block.parent}\'');
$this->smarty->fetch('027_parent.tpl'); $this->smarty->fetch('027_parent.tpl');
} }
@@ -1149,7 +1149,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockWrongBlockName_036() public function testSmartyBlockWrongBlockName_036()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('$smarty.block is not defined'); $this->expectExceptionMessage('$smarty.block is not defined');
$this->smarty->fetch('036_parent.tpl'); $this->smarty->fetch('036_parent.tpl');
} }
@@ -1158,7 +1158,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyParentBlockCalledInParent_036_1() public function testSmartyParentBlockCalledInParent_036_1()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('inheritance: illegal \'{$smarty.block.parent}\' used in child template'); $this->expectExceptionMessage('inheritance: illegal \'{$smarty.block.parent}\' used in child template');
$this->smarty->fetch('036_1_parent.tpl'); $this->smarty->fetch('036_1_parent.tpl');
} }
@@ -1167,7 +1167,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyParentBlockCalledInParent_036_2() public function testSmartyParentBlockCalledInParent_036_2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('inheritance: illegal \'{block_parent}\' used in child template'); $this->expectExceptionMessage('inheritance: illegal \'{block_parent}\' used in child template');
$this->smarty->fetch('036_2_parent.tpl'); $this->smarty->fetch('036_2_parent.tpl');
} }
@@ -1176,7 +1176,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyParentBlockCalledInParent_036_3() public function testSmartyParentBlockCalledInParent_036_3()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('inheritance: illegal \'{parent}\' used in child template'); $this->expectExceptionMessage('inheritance: illegal \'{parent}\' used in child template');
$this->smarty->fetch('036_3_parent.tpl'); $this->smarty->fetch('036_3_parent.tpl');
} }
@@ -1186,7 +1186,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/ */
public function testSmartyBlockMissigBlockName_037() public function testSmartyBlockMissigBlockName_037()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('$smarty.block is not defined'); $this->expectExceptionMessage('$smarty.block is not defined');
$this->smarty->fetch('037_parent.tpl'); $this->smarty->fetch('037_parent.tpl');
} }

View File

@@ -165,7 +165,7 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
*/ */
public function testConfigSyntaxError_009() public function testConfigSyntaxError_009()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('Syntax error in config file'); $this->expectExceptionMessage('Syntax error in config file');
$this->smarty->fetch('009_error.tpl'); $this->smarty->fetch('009_error.tpl');
} }

View File

@@ -43,7 +43,7 @@ class CompileDelimiterTest extends PHPUnit_Smarty
public function testLeftDelimiterError() public function testLeftDelimiterError()
{ {
$this->expectException('SmartyCompilerException'); $this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('nocache option not allowed'); $this->expectExceptionMessage('nocache option not allowed');
$tpl = $this->smarty->createTemplate('string:x{ldelim nocache}x'); $tpl = $this->smarty->createTemplate('string:x{ldelim nocache}x');
$this->assertEquals('x{x', $this->smarty->fetch($tpl)); $this->assertEquals('x{x', $this->smarty->fetch($tpl));

View File

@@ -45,7 +45,7 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty
*/ */
public function testFetchInvalidUri() public function testFetchInvalidUri()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('{fetch} cannot read resource \'https://foo.smarty.net/foo.dat\''); $this->expectExceptionMessage('{fetch} cannot read resource \'https://foo.smarty.net/foo.dat\'');
$this->smarty->fetch('string:{fetch file="https://foo.smarty.net/foo.dat"}'); $this->smarty->fetch('string:{fetch file="https://foo.smarty.net/foo.dat"}');
} }
@@ -58,7 +58,7 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty
*/ */
public function testFetchSecurity() public function testFetchSecurity()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('not trusted file path'); $this->expectExceptionMessage('not trusted file path');
$this->cleanDirs(); $this->cleanDirs();
$dir=$this->smarty->getTemplateDir(); $dir=$this->smarty->getTemplateDir();
@@ -73,7 +73,7 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty
*/ */
public function testFetchSecurity2() public function testFetchSecurity2()
{ {
$this->expectException('SmartyException'); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('not trusted file path'); $this->expectExceptionMessage('not trusted file path');
$this->cleanDirs(); $this->cleanDirs();
$this->smarty->getTemplateDir(); $this->smarty->getTemplateDir();

View File

@@ -19,7 +19,7 @@ class PluginModifierExplodeTest extends \PHPUnit_Smarty
/** /**
* @return void * @return void
* @throws \SmartyException * @throws \Smarty\Exception
* *
* @dataProvider explodeDataProvider * @dataProvider explodeDataProvider
*/ */

Some files were not shown because too many files have changed in this diff Show More