src/Template/* to PSR-4

This commit is contained in:
Simon Wisselink
2022-12-22 21:23:22 +01:00
parent d88175de3e
commit 0fc2b3726b
83 changed files with 3473 additions and 3458 deletions

View File

@@ -1,5 +1,8 @@
<?php
use Smarty\Template;
use Smarty\Template\Source;
/**
* Extends All Resource
* Resource Implementation modifying the extends-Resource to walk
@@ -13,12 +16,12 @@ class Smarty_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$uid = '';
$sources = array();

View File

@@ -70,7 +70,7 @@ cannot have both custom function `{func}` and block function
* Purpose: translate a block of text
* -------------------------------------------------------------
*/
function smarty_block_translate($params, $content, Smarty_Internal_Template $template, &$repeat)
function smarty_block_translate($params, $content, \Smarty\Template $template, &$repeat)
{
// only output on the closing tag
if(!$repeat){

View File

@@ -14,18 +14,18 @@ template you\'re addressing: `foobarxyz:yourtemplate.tpl`.
If a Resource\'s templates should not be run through the Smarty
compiler, the Custom Resource may extend `Smarty_Resource_Uncompiled`.
The Resource Handler must then implement the function
`renderUncompiled(Smarty_Internal_Template $_template)`. `$_template` is
`renderUncompiled(\Smarty\Template $_template)`. `$_template` is
a reference to the current template and contains all assigned variables
which the implementor can access via
`$_template->smarty->getTemplateVars()`. These Resources simply echo
their rendered content to the output stream. The rendered output will be
output-cached if the Smarty instance was configured accordingly. See
`libs/sysplugins/smarty_internal_resource_php.php` for an example.
`src/Resource/PhpPlugin.php` for an example.
If the Resource\'s compiled templates should not be cached on disk, the
Custom Resource may extend `Smarty_Resource_Recompiled`. These Resources
are compiled every time they are accessed. This may be an expensive
overhead. See `libs/sysplugins/smarty_internal_resource_eval.php` for an
overhead. See `src/Resource/StringEval.php` for an
example.

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsBlock
*/
use Smarty\Template;
/**
* Smarty {textformat}{/textformat} block plugin
* Type: block function
@@ -25,14 +28,14 @@
*
* @param array $params parameters
* @param string $content contents of the block
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
* @param boolean &$repeat repeat flag
*
* @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com>
* @throws \SmartyException
*/
function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat)
function smarty_block_textformat($params, $content, Template $template, &$repeat)
{
if (is_null($content)) {
return;

View File

@@ -5,20 +5,23 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {counter} function plugin
* Type: function
* Name: counter
* Purpose: print out a counter value
*
* @author Monte Ohrt <monte at ohrt dot com>
* @param array $params parameters
* @param Template $template template object
*
* @return string|null
*@link https://www.smarty.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
*
* @return string|null
* @author Monte Ohrt <monte at ohrt dot com>
*/
function smarty_function_counter($params, $template)
{

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {cycle} function plugin
* Type: function
@@ -37,7 +40,7 @@
* @version 1.3
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @return string|null
*/

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {fetch} plugin
* Type: function
@@ -16,7 +19,7 @@
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @throws SmartyException
* @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_checkboxes} function plugin
* File: function.html_checkboxes.php
@@ -36,13 +39,13 @@
* @version 1.0
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
function smarty_function_html_checkboxes($params, Template $template)
{
$name = 'checkbox';
$values = null;

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_image} function plugin
* Type: function
@@ -28,13 +31,13 @@
* @version 1.0
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @throws SmartyException
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_image($params, Smarty_Internal_Template $template)
function smarty_function_html_image($params, Template $template)
{
$alt = '';
$file = '';

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_options} function plugin
* Type: function
@@ -28,13 +31,13 @@
*
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_options($params, Smarty_Internal_Template $template)
function smarty_function_html_options($params, Template $template)
{
$name = null;
$values = null;

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_radios} function plugin
* File: function.html_radios.php
@@ -36,13 +39,13 @@
* @version 1.0
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @return string
* @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/
function smarty_function_html_radios($params, Smarty_Internal_Template $template)
function smarty_function_html_radios($params, Template $template)
{
$name = 'radio';
$values = null;

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_select_date} plugin
* Type: function
@@ -37,12 +40,12 @@
*
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string
* @throws \SmartyException
*/
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
function smarty_function_html_select_date($params, Template $template)
{
// generate timestamps used for month names only
static $_month_timestamps = null;

View File

@@ -5,6 +5,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {html_select_time} function plugin
* Type: function
@@ -18,13 +21,13 @@
*
* @param array $params parameters
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string
* @uses smarty_make_timestamp()
* @throws \SmartyException
*/
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
function smarty_function_html_select_time($params, Template $template)
{
$prefix = 'Time_';
$field_array = null;
@@ -139,7 +142,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
'';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given
foreach (array(
@@ -154,19 +157,19 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
$_meridian = isset($params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) ?
(' ' . $params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) : '';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
} else {
// no date found, use NOW
list($_year, $_month, $_day) = $time = explode('-', date('Y-m-d'));
[$_year, $_month, $_day] = $time = explode('-', date('Y-m-d'));
}
} elseif ($time === null) {
if (array_key_exists('time', $params)) {
$_hour = $_minute = $_second = $time = null;
} else {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s'));
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s'));
}
} else {
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
[$_hour, $_minute, $_second] = $time = explode('-', date('H-i-s', $time));
}
// generate hour <select>
if ($display_hours) {

View File

@@ -6,6 +6,9 @@
* @package Smarty
* @subpackage PluginsFunction
*/
use Smarty\Template;
/**
* Smarty {math} function plugin
* Type: function
@@ -17,7 +20,7 @@
* @author Monte Ohrt <monte at ohrt dot com>
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @return string|null
*/

View File

@@ -5,15 +5,18 @@
* @package Smarty
* @subpackage PluginsFilter
*/
use Smarty\Template;
/**
* Smarty htmlspecialchars variablefilter plugin
*
* @param string $source input string
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string filtered output
*/
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
function smarty_variablefilter_htmlspecialchars($source, Template $template)
{
return htmlspecialchars($source, ENT_QUOTES, \Smarty\Smarty::$_CHARSET);
}

View File

@@ -84,9 +84,9 @@ class Block
/**
* Compiled block code overloaded by {block} class
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
*/
public function callBlock(\Smarty_Internal_Template $tpl)
public function callBlock(\Smarty\Template $tpl)
{
}
}

View File

@@ -3,8 +3,8 @@
namespace Smarty\Cacheresource;
use Smarty\Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Cached;
use Smarty\Template;
use Smarty\Template\Cached;
/**
* Smarty Internal Plugin
@@ -32,64 +32,64 @@ abstract class Base
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Cached $cached cached object
* @param Template $_template template object
*
* @return void
*/
abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
abstract public function populate(Cached $cached, Template $_template);
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached
* @param Cached $cached
*
* @return void
*/
abstract public function populateTimestamp(Smarty_Template_Cached $cached);
abstract public function populateTimestamp(Cached $cached);
/**
* Read the cached template and process header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param Template $_template template object
* @param Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(
Smarty_Internal_Template $_template,
Smarty_Template_Cached $cached = null,
Template $_template,
Cached $cached = null,
$update = false
);
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
abstract public function storeCachedContent(Smarty_Internal_Template $_template, $content);
abstract public function storeCachedContent(Template $_template, $content);
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
*
* @return string content
*/
abstract public function retrieveCachedContent(Smarty_Internal_Template $_template);
abstract public function retrieveCachedContent(Template $_template);
/**
* Return cached content
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
*
* @return null|string
*/
public function getCachedContent(Smarty_Internal_Template $_template)
public function getCachedContent(Template $_template)
{
if ($_template->cached->handler->process($_template)) {
ob_start();
@@ -125,11 +125,11 @@ abstract class Base
/**
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
* @param Cached $cached
*
* @return bool|null
*/
public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
public function locked(Smarty $smarty, Cached $cached)
{
// theoretically locking_timeout should be checked against time_limit (max_execution_time)
$start = microtime(true);
@@ -149,11 +149,11 @@ abstract class Base
* Check is cache is locked for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
* @param Cached $cached
*
* @return bool
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
// check if lock exists
return false;
@@ -163,11 +163,11 @@ abstract class Base
* Lock cache for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
* @param Cached $cached
*
* @return bool
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function acquireLock(Smarty $smarty, Cached $cached)
{
// create lock
return true;
@@ -177,11 +177,11 @@ abstract class Base
* Unlock cache for this template
*
* @param Smarty $smarty
* @param Smarty_Template_Cached $cached
* @param Cached $cached
*
* @return bool
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function releaseLock(Smarty $smarty, Cached $cached)
{
// release lock
return true;

View File

@@ -9,7 +9,7 @@ namespace Smarty\Cacheresource;
* @subpackage Cacher
*/
use Smarty_Internal_Template;
use Smarty\Template;
/**
* Cache Handler API
@@ -80,12 +80,12 @@ abstract class Custom extends Base
/**
* populate Cached Object with metadata from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param \Smarty\Template\Cached $cached cached object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
public function populate(\Smarty\Template\Cached $cached, Template $_template)
{
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
@@ -100,11 +100,11 @@ abstract class Custom extends Base
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached
* @param \Smarty\Template\Cached $cached
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
public function populateTimestamp(\Smarty\Template\Cached $cached)
{
$mtime =
$this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
@@ -129,14 +129,14 @@ abstract class Custom extends Base
/**
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param \Smarty\Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
$update = false
) {
@@ -166,12 +166,12 @@ abstract class Custom extends Base
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
public function storeCachedContent(Template $_template, $content)
{
return $this->save(
$_template->cached->filepath,
@@ -186,11 +186,11 @@ abstract class Custom extends Base
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
*
* @return string|boolean content
*/
public function retrieveCachedContent(Smarty_Internal_Template $_template)
public function retrieveCachedContent(Template $_template)
{
$content = $_template->cached->content ?: null;
if ($content === null) {

View File

@@ -3,8 +3,8 @@
namespace Smarty\Cacheresource;
use Smarty\Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Cached;
use Smarty\Template;
use Smarty\Template\Cached;
/**
* Smarty Internal Plugin CacheResource File
@@ -27,12 +27,12 @@ class File extends Base
/**
* populate Cached Object with metadata from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Cached $cached cached object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
public function populate(Cached $cached, Template $_template)
{
$source = &$_template->source;
$smarty = &$_template->smarty;
@@ -80,11 +80,11 @@ class File extends Base
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
public function populateTimestamp(Cached $cached)
{
$cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) {
@@ -95,15 +95,15 @@ class File extends Base
/**
* Read the cached template and process its header
*
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Cached|null $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
Template $_smarty_tpl,
Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
@@ -118,13 +118,13 @@ class File extends Base
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
* @param string $content content to cache
*
* @return bool success
* @throws \SmartyException
*/
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
public function storeCachedContent(Template $_template, $content)
{
if ($_template->smarty->writeFile($_template->cached->filepath, $content) === true) {
if (function_exists('opcache_invalidate')
@@ -147,11 +147,11 @@ class File extends Base
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
*
* @return string content
*/
public function retrieveCachedContent(Smarty_Internal_Template $_template)
public function retrieveCachedContent(Template $_template)
{
if (is_file($_template->cached->filepath)) {
return file_get_contents($_template->cached->filepath);
@@ -298,11 +298,11 @@ class File extends Base
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
clearstatcache(true, $cached->lock_id ?? '');
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
@@ -317,11 +317,11 @@ class File extends Base
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return void
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function acquireLock(Smarty $smarty, Cached $cached)
{
$cached->is_locked = true;
touch($cached->lock_id);
@@ -331,11 +331,11 @@ class File extends Base
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return void
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function releaseLock(Smarty $smarty, Cached $cached)
{
$cached->is_locked = false;
@unlink($cached->lock_id);

View File

@@ -3,8 +3,8 @@
namespace Smarty\Cacheresource;
use Smarty\Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Cached;
use Smarty\Template;
use Smarty\Template\Cached;
/**
* Smarty Internal Plugin
@@ -54,12 +54,12 @@ abstract class KeyValueStore extends Base
/**
* populate Cached Object with meta data from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
* @param Cached $cached cached object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
public function populate(Cached $cached, Template $_template)
{
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
@@ -69,11 +69,11 @@ abstract class KeyValueStore extends Base
/**
* populate Cached Object with timestamp and exists from Resource
*
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return void
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
public function populateTimestamp(Cached $cached)
{
if (!$this->fetch(
$cached->filepath,
@@ -95,15 +95,15 @@ abstract class KeyValueStore extends Base
/**
* Read the cached template and process the header
*
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Cached|null $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
Smarty_Template_Cached $cached = null,
Template $_smarty_tpl,
Cached $cached = null,
$update = false
) {
if (!$cached) {
@@ -135,12 +135,12 @@ abstract class KeyValueStore extends Base
/**
* Write the rendered template output to cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function storeCachedContent(Smarty_Internal_Template $_template, $content)
public function storeCachedContent(Template $_template, $content)
{
$this->addMetaTimestamp($content);
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
@@ -149,11 +149,11 @@ abstract class KeyValueStore extends Base
/**
* Read cached template from cache
*
* @param Smarty_Internal_Template $_template template object
* @param Template $_template template object
*
* @return string|false content
*/
public function retrieveCachedContent(Smarty_Internal_Template $_template)
public function retrieveCachedContent(Template $_template)
{
$content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null;
@@ -460,11 +460,11 @@ abstract class KeyValueStore extends Base
* Check is cache is locked for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
$key = 'LOCK#' . $cached->filepath;
$data = $this->read(array($key));
@@ -475,11 +475,11 @@ abstract class KeyValueStore extends Base
* Lock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return bool|void
*/
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function acquireLock(Smarty $smarty, Cached $cached)
{
$cached->is_locked = true;
$key = 'LOCK#' . $cached->filepath;
@@ -490,11 +490,11 @@ abstract class KeyValueStore extends Base
* Unlock cache for this template
*
* @param Smarty $smarty Smarty object
* @param Smarty_Template_Cached $cached cached object
* @param Cached $cached cached object
*
* @return void
*/
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function releaseLock(Smarty $smarty, Cached $cached)
{
$cached->is_locked = false;
$key = 'LOCK#' . $cached->filepath;

View File

@@ -10,7 +10,6 @@
namespace Smarty\Compile;
use Smarty_Internal_Template;
use Smarty\Compiler\Template;
/**
@@ -144,11 +143,11 @@ class ExtendsTag extends Inheritance {
/**
* Create source code for {extends} from source components array
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string
*/
public static function extendsSourceArrayCode(Smarty_Internal_Template $template) {
public static function extendsSourceArrayCode(\Smarty\Template $template) {
$resources = [];
foreach ($template->source->components as $source) {
$resources[] = $source->resource;

View File

@@ -10,9 +10,6 @@
namespace Smarty\Compile;
use Smarty_Internal_Compile_Foreach;
use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Foreachclose Class
*
@@ -44,7 +41,7 @@ class ForeachClose extends Base {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n";
/* @var \Smarty\Compile\Smarty_Internal_Compile_Foreach $foreachCompiler */
/* @var \Smarty\Compile\ForeachTag $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore(1);
$output .= "?>";

View File

@@ -12,9 +12,8 @@ namespace Smarty\Compile;
use Smarty\Compiler\Template;
use Smarty\Smarty;
use Smarty_Internal_Template;
use Smarty\Compile\Base;
use Smarty_Template_Compiled;
use Smarty\Template\Compiled;
/**
* Smarty Internal Plugin Compile Include Class
@@ -207,7 +206,7 @@ class IncludeTag extends Base {
// we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */
/* @var \Smarty\Template $tpl */
$tpl = new $compiler->smarty->template_class(
trim($fullResourceName, '"\''),
$compiler->smarty,
@@ -288,7 +287,7 @@ class IncludeTag extends Base {
* Compile inline sub template
*
* @param \Smarty\Compiler\Template $compiler
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param string $t_hash
*
* @return bool
@@ -297,7 +296,7 @@ class IncludeTag extends Base {
*/
private function compileInlineTemplate(
Template $compiler,
Smarty_Internal_Template $tpl,
\Smarty\Template $tpl,
$t_hash
) {
$uid = $tpl->source->type . $tpl->source->uid;
@@ -306,7 +305,7 @@ class IncludeTag extends Base {
if (isset($compiler->template->inheritance)) {
$tpl->inheritance = clone $compiler->template->inheritance;
}
$tpl->compiled = new Smarty_Template_Compiled();
$tpl->compiled = new Compiled();
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler();
// save unique function name

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Template;
namespace Smarty\Compiler;
/**
* Smarty Internal Extension
@@ -13,10 +13,19 @@ namespace Smarty\Template;
*/
class CodeFrame
{
/**
* @var \Smarty\Template
*/
private $_template;
public function __construct(\Smarty\Template $_template) {
$this->_template = $_template;
}
/**
* Create code frame for compiled and cached templates
*
* @param \Smarty_Internal_Template $_template
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
@@ -25,7 +34,6 @@ class CodeFrame
* @return string
*/
public function create(
\Smarty_Internal_Template $_template,
$content = '',
$functions = '',
$cache = false,
@@ -35,19 +43,19 @@ class CodeFrame
$properties[ 'version' ] = \Smarty::SMARTY_VERSION;
$properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
if (!$cache) {
$properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
$properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
$properties[ 'includes' ] = $_template->compiled->includes;
$properties[ 'has_nocache_code' ] = $this->_template->compiled->has_nocache_code;
$properties[ 'file_dependency' ] = $this->_template->compiled->file_dependency;
$properties[ 'includes' ] = $this->_template->compiled->includes;
} else {
$properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code;
$properties[ 'file_dependency' ] = $_template->cached->file_dependency;
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
$properties[ 'has_nocache_code' ] = $this->_template->cached->has_nocache_code;
$properties[ 'file_dependency' ] = $this->_template->cached->file_dependency;
$properties[ 'cache_lifetime' ] = $this->_template->cache_lifetime;
}
$output = sprintf(
"<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
$properties[ 'version' ],
date("Y-m-d H:i:s"),
str_replace('*/', '* /', $_template->source->filepath)
str_replace('*/', '* /', $this->_template->source->filepath)
);
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
@@ -55,13 +63,13 @@ class CodeFrame
$output .= "if ({$dec}) {\n";
$output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
if (!$cache && !empty($compiler->tpl_function)) {
$output .= '$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions($_smarty_tpl, ';
$output .= '$_smarty_tpl->smarty->getRuntime(\'TplFunction\')->registerTplFunctions($_smarty_tpl, ';
$output .= var_export($compiler->tpl_function, true);
$output .= ");\n";
}
if ($cache && isset($_template->smarty->ext->_tplFunction)) {
$output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
if ($cache && $this->_template->smarty->hasRuntime('TplFunction')) {
$output .= "\$_smarty_tpl->smarty->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " .
var_export($this->_template->smarty->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n";
}
$output .= "?>";
$output .= $content;

View File

@@ -13,7 +13,7 @@ namespace Smarty\Compiler;
use Smarty;
use Smarty_Internal_ConfigFileLexer;
use Smarty_Internal_ConfigFileParser;
use Smarty_Internal_Template;
use Smarty\Template;
use SmartyCompilerException;
/**
@@ -62,7 +62,7 @@ class ConfigFile {
/**
* Smarty object
*
* @var Smarty_Internal_Template object
* @var Template object
*/
public $template;
@@ -93,12 +93,12 @@ class ConfigFile {
/**
* Method to compile Smarty config source.
*
* @param Smarty_Internal_Template $template
* @param Template $template
*
* @return bool true if compiling succeeded, false if it failed
* @throws \SmartyException
*/
public function compileTemplate(Smarty_Internal_Template $template) {
public function compileTemplate(Template $template) {
$this->template = $template;
$this->template->compiled->file_dependency[$this->template->source->uid] =
[
@@ -161,9 +161,9 @@ class ConfigFile {
date("Y-m-d H:i:s"),
str_replace('*/', '* /', $this->template->source->filepath)
);
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
$code = '<?php $_smarty_tpl->_loadConfigVars(' .
var_export($this->config_data, true) . '); ?>';
return $template_header . $this->createCodeFrame($code);
return $template_header . $this->template->createCodeFrame($code);
}
/**

View File

@@ -386,7 +386,7 @@ class Template {
/**
* Compile template source and run optional post filter
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty\Compiler\Template $parent_compiler
*
@@ -473,7 +473,7 @@ class Template {
public function postFilter($code) {
// run post filter if on code
if (!empty($code) && isset($this->smarty->registered_filters['post'])) {
return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
return $this->smarty->runFilter('post', $code, $this->template);
} else {
return $code;
}
@@ -490,7 +490,7 @@ class Template {
public function preFilter($_content) {
// run pre filter if required
if ($_content !== '' && isset($this->smarty->registered_filters['pre'])) {
return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
return $this->smarty->runFilter('pre', $_content, $this->template);
} else {
return $_content;
}
@@ -1375,8 +1375,8 @@ class Template {
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
if (isset($this->parent_compiler->tpl_function[$tag])
|| (isset($this->template->smarty->ext->_tplFunction)
&& $this->template->smarty->ext->_tplFunction->getTplFunction($this->template, $tag) !== false)
|| ($this->template->smarty->hasRuntime('TplFunction')
&& $this->template->smarty->getRuntime('TplFunction')->getTplFunction($this->template, $tag) !== false)
) {
// template defined by {template} tag
$args['_attr']['name'] = "'{$tag}'";

View File

@@ -36,7 +36,7 @@ abstract class Data
*
* @var string
*/
public $template_class = 'Smarty_Internal_Template';
public $template_class = 'Smarty\Template';
/**
* template variables
@@ -48,7 +48,7 @@ abstract class Data
/**
* parent template (if any)
*
* @var Smarty|Smarty_Internal_Template|Smarty_Data
* @var Smarty|Template|Smarty_Data
*/
public $parent = null;
@@ -88,7 +88,7 @@ abstract class Data
/**
*
*
* @var Smarty_Internal_Template $this
* @var Template $this
*/
$this->_assignInScope($tpl_var, $value, $nocache);
} else {
@@ -461,8 +461,8 @@ abstract class Data
{
/* @var \Smarty $smarty */
$smarty = $this->_getSmartyObj();
/* @var \Smarty_Internal_Template $confObj */
$confObj = new Smarty_Internal_Template($config_file, $smarty, $this, null, null, null, null, true);
/* @var \Smarty\Template $confObj */
$confObj = new Template($config_file, $smarty, $this, null, null, null, null, true);
$confObj->caching = Smarty::CACHING_OFF;
$confObj->source->config_sections = $sections;
$confObj->source->scope = $scope;

View File

@@ -50,10 +50,10 @@ class Debug extends Data
/**
* Start logging template
*
* @param \Smarty_Internal_Template $template template
* @param \Smarty\Template $template template
* @param null $mode true: display false: fetch null: subtemplate
*/
public function start_template(\Smarty_Internal_Template $template, $mode = null)
public function start_template(\Smarty\Template $template, $mode = null)
{
if (isset($mode) && !$template->_isSubTpl()) {
$this->index++;
@@ -67,9 +67,9 @@ class Debug extends Data
/**
* End logging of cache time
*
* @param \Smarty_Internal_Template $template cached template
* @param \Smarty\Template $template cached template
*/
public function end_template(\Smarty_Internal_Template $template)
public function end_template(\Smarty\Template $template)
{
$key = $this->get_key($template);
$this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
@@ -79,9 +79,9 @@ class Debug extends Data
/**
* Start logging of compile time
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function start_compile(\Smarty_Internal_Template $template)
public function start_compile(\Smarty\Template $template)
{
static $_is_stringy = array('string' => true, 'eval' => true);
if (!empty($template->compiler->trace_uid)) {
@@ -101,9 +101,9 @@ class Debug extends Data
/**
* End logging of compile time
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function end_compile(\Smarty_Internal_Template $template)
public function end_compile(\Smarty\Template $template)
{
if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid;
@@ -120,9 +120,9 @@ class Debug extends Data
/**
* Start logging of render time
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function start_render(\Smarty_Internal_Template $template)
public function start_render(\Smarty\Template $template)
{
$key = $this->get_key($template);
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
@@ -131,9 +131,9 @@ class Debug extends Data
/**
* End logging of compile time
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function end_render(\Smarty_Internal_Template $template)
public function end_render(\Smarty\Template $template)
{
$key = $this->get_key($template);
$this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
@@ -143,9 +143,9 @@ class Debug extends Data
/**
* Start logging of cache time
*
* @param \Smarty_Internal_Template $template cached template
* @param \Smarty\Template $template cached template
*/
public function start_cache(\Smarty_Internal_Template $template)
public function start_cache(\Smarty\Template $template)
{
$key = $this->get_key($template);
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
@@ -154,9 +154,9 @@ class Debug extends Data
/**
* End logging of cache time
*
* @param \Smarty_Internal_Template $template cached template
* @param \Smarty\Template $template cached template
*/
public function end_cache(\Smarty_Internal_Template $template)
public function end_cache(\Smarty\Template $template)
{
$key = $this->get_key($template);
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
@@ -166,9 +166,9 @@ class Debug extends Data
/**
* Register template object
*
* @param \Smarty_Internal_Template $template cached template
* @param \Smarty\Template $template cached template
*/
public function register_template(\Smarty_Internal_Template $template)
public function register_template(\Smarty\Template $template)
{
}
@@ -184,7 +184,7 @@ class Debug extends Data
/**
* Opens a window for the Smarty Debugging Console and display the data
*
* @param \Smarty_Internal_Template|\Smarty $obj object to debug
* @param \Smarty\Template|\Smarty $obj object to debug
* @param bool $full
*
* @throws \Exception
@@ -228,7 +228,7 @@ class Debug extends Data
$_config_vars = $ptr->config_vars;
ksort($_config_vars);
$debugging = $smarty->debugging;
$_template = new \Smarty_Internal_Template($debObj->debug_tpl, $debObj);
$_template = new \Smarty\Template($debObj->debug_tpl, $debObj);
if ($obj->_isTplObj()) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
@@ -254,7 +254,7 @@ class Debug extends Data
/**
* Recursively gets variables from all template/data scopes
*
* @param \Smarty_Internal_Template|\Smarty_Data $obj object to debug
* @param \Smarty\Template|\Smarty_Data $obj object to debug
*
* @return \StdClass
*/
@@ -338,11 +338,11 @@ class Debug extends Data
/**
* Return key into $template_data for template
*
* @param \Smarty_Internal_Template $template template object
* @param \Smarty\Template $template template object
*
* @return string key into $template_data
*/
private function get_key(\Smarty_Internal_Template $template)
private function get_key(\Smarty\Template $template)
{
static $_is_stringy = array('string' => true, 'eval' => true);
// calculate Uid if not already done
@@ -362,9 +362,9 @@ class Debug extends Data
/**
* Ignore template
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function ignore(\Smarty_Internal_Template $template)
public function ignore(\Smarty\Template $template)
{
// calculate Uid if not already done
if ($template->source->uid === '') {
@@ -407,12 +407,12 @@ class Debug extends Data
/**
* @param array $_is_stringy
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
* @param string $key
*
* @return void
*/
private function saveTemplateData(array $_is_stringy, \Smarty_Internal_Template $template, string $key): void {
private function saveTemplateData(array $_is_stringy, \Smarty\Template $template, string $key): void {
if (isset($_is_stringy[$template->source->type])) {
$this->template_data[$this->index][$key]['name'] =
'\'' . substr($template->source->name, 0, 25) . '...\'';

View File

@@ -138,7 +138,7 @@ abstract class BasePlugin
/**
* modify template_resource according to resource handlers specifications
*
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
* @param \Smarty\Template|\Smarty $obj Smarty instance
* @param string $template_resource template_resource to extract resource handler and
* name of
*
@@ -166,45 +166,45 @@ abstract class BasePlugin
* wrapper for backward compatibility to versions < 3.1.22
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param \Smarty_Internal_Template $_template template object
* @param \Smarty\Template $_template template object
* @param \Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return \Smarty_Template_Source Source Object
* @return \Smarty\Template\Source Source Object
* @throws \SmartyException
*/
public static function source(
\Smarty_Internal_Template $_template = null,
\Smarty\Template $_template = null,
\Smarty $smarty = null,
$template_resource = null
) {
return \Smarty_Template_Source::load($_template, $smarty, $template_resource);
return \Smarty\Template\Source::load($_template, $smarty, $template_resource);
}
/**
* Load template's source into current template object
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string template source
* @throws \SmartyException if source cannot be loaded
*/
abstract public function getContent(\Smarty_Template_Source $source);
abstract public function getContent(\Smarty\Template\Source $source);
/**
* populate Source Object with meta data from Resource
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty_Internal_Template $_template template object
* @param \Smarty\Template\Source $source source object
* @param \Smarty\Template $_template template object
*/
abstract public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null);
abstract public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null);
/**
* populate Source Object with timestamp and exists from Resource
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*/
public function populateTimestamp(\Smarty_Template_Source $source)
public function populateTimestamp(\Smarty\Template\Source $source)
{
// intentionally left blank
}
@@ -242,11 +242,11 @@ abstract class BasePlugin
/**
* Determine basename for compiled filename
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string resource's basename
*/
public function getBasename(\Smarty_Template_Source $source)
public function getBasename(\Smarty\Template\Source $source)
{
return basename(preg_replace('![^\w]+!', '_', $source->name));
}

View File

@@ -9,8 +9,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
use SmartyException;
/**
@@ -20,7 +20,7 @@ use SmartyException;
* @package Smarty
* @subpackage TemplateResources
*/
abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
abstract class CustomPlugin extends BasePlugin {
/**
* fetch template and its modification time from data source
@@ -47,10 +47,10 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
public function populate(Source $source, Template $_template = null) {
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
$source->uid = sha1($source->type . ':' . $source->name);
$mtime = $this->fetchTimestamp($source->name);
@@ -69,12 +69,12 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
/**
* Load template's source into current template object
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
$this->fetch($source->name, $content, $timestamp);
if (isset($content)) {
return $content;
@@ -85,11 +85,11 @@ abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source) {
public function getBasename(Source $source) {
return basename($this->generateSafeName($source->name));
}

View File

@@ -24,12 +24,12 @@ class ExtendsPlugin extends BasePlugin
/**
* populate Source Object with metadata from Resource
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty_Internal_Template $_template template object
* @param \Smarty\Template\Source $source source object
* @param \Smarty\Template $_template template object
*
* @throws \SmartyException
*/
public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null)
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
{
$uid = '';
$sources = array();
@@ -37,8 +37,8 @@ class ExtendsPlugin extends BasePlugin
$smarty = &$source->smarty;
$exists = true;
foreach ($components as $component) {
/* @var \Smarty_Template_Source $_s */
$_s = \Smarty_Template_Source::load(null, $smarty, $component);
/* @var \Smarty\Template\Source $_s */
$_s = \Smarty\Template\Source::load(null, $smarty, $component);
if ($_s->type === 'php') {
throw new \SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
}
@@ -60,12 +60,12 @@ class ExtendsPlugin extends BasePlugin
/**
* populate Source Object with timestamp and exists from Resource
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*/
public function populateTimestamp(\Smarty_Template_Source $source)
public function populateTimestamp(\Smarty\Template\Source $source)
{
$source->exists = true;
/* @var \Smarty_Template_Source $_s */
/* @var \Smarty\Template\Source $_s */
foreach ($source->components as $_s) {
$source->exists = $source->exists && $_s->exists;
}
@@ -75,19 +75,19 @@ class ExtendsPlugin extends BasePlugin
/**
* Load template's source from files into current template object
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string template source
* @throws \SmartyException if source cannot be loaded
*/
public function getContent(\Smarty_Template_Source $source)
public function getContent(\Smarty\Template\Source $source)
{
if (!$source->exists) {
throw new \SmartyException("Unable to load template '{$source->type}:{$source->name}'");
}
$_components = array_reverse($source->components);
$_content = '';
/* @var \Smarty_Template_Source $_s */
/* @var \Smarty\Template\Source $_s */
foreach ($_components as $_s) {
// read content
$_content .= $_s->getContent();
@@ -98,11 +98,11 @@ class ExtendsPlugin extends BasePlugin
/**
* Determine basename for compiled filename
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string resource's basename
*/
public function getBasename(\Smarty_Template_Source $source)
public function getBasename(\Smarty\Template\Source $source)
{
return str_replace(':', '.', basename($source->filepath));
}

View File

@@ -10,8 +10,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
use SmartyException;
/**
@@ -21,17 +21,17 @@ use SmartyException;
* @package Smarty
* @subpackage TemplateResources
*/
class FilePlugin extends Smarty\Resource\BasePlugin {
class FilePlugin extends BasePlugin {
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @throws \SmartyException
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
public function populate(Source $source, Template $_template = null) {
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
@@ -51,9 +51,9 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
/**
* populate Source Object with timestamp and exists from Resource
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*/
public function populateTimestamp(Smarty_Template_Source $source) {
public function populateTimestamp(Source $source) {
if (!$source->exists) {
$source->timestamp = $source->exists = is_file($source->filepath);
}
@@ -65,12 +65,12 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
/**
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
if ($source->exists) {
return file_get_contents($source->filepath);
}
@@ -83,24 +83,24 @@ class FilePlugin extends Smarty\Resource\BasePlugin {
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source) {
public function getBasename(Source $source) {
return basename($source->filepath);
}
/**
* build template filepath by traversing the template_dir array
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @return string fully qualified filepath
* @throws SmartyException
*/
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
protected function buildFilepath(Source $source, Template $_template = null) {
$file = $source->name;
// absolute file ?
if ($file[0] === '/' || $file[1] === ':') {

View File

@@ -2,9 +2,9 @@
namespace Smarty\Resource;
use Smarty_Internal_Template;
use Smarty_Template_Compiled;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
use Smarty\Template\Compiled;
use SmartyException;
/**
@@ -49,12 +49,12 @@ class PhpPlugin extends FilePlugin {
/**
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
if ($source->exists) {
return '';
}
@@ -64,10 +64,10 @@ class PhpPlugin extends FilePlugin {
/**
* populate compiled object with compiled filepath
*
* @param Smarty_Template_Compiled $compiled compiled object
* @param Smarty_Internal_Template $_template template object (is ignored)
* @param Compiled $compiled compiled object
* @param Template $_template template object (is ignored)
*/
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
$compiled->filepath = $_template->source->filepath;
$compiled->timestamp = $_template->source->timestamp;
$compiled->exists = $_template->source->exists;
@@ -82,13 +82,13 @@ class PhpPlugin extends FilePlugin {
/**
* Render and output the template (without using the compiler)
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @return void
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
*/
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) {
public function renderUncompiled(Source $source, Template $_template) {
if (!$source->smarty->allow_php_templates) {
throw new SmartyException('PHP templates are disabled');
}
@@ -107,7 +107,7 @@ class PhpPlugin extends FilePlugin {
/**
*
*
* @var Smarty_Internal_Template $_smarty_template
* @var Template $_smarty_template
* used in included file
*/
$_smarty_template = $_template;

View File

@@ -10,8 +10,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Compiled;
use Smarty\Template;
use Smarty\Template\Compiled;
/**
* Smarty Resource Plugin
@@ -39,11 +39,11 @@ abstract class RecompiledPlugin extends BasePlugin {
/**
* compile template from source
*
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
*
* @throws Exception
*/
public function process(Smarty_Internal_Template $_smarty_tpl) {
public function process(Template $_smarty_tpl) {
$compiled = &$_smarty_tpl->compiled;
$compiled->file_dependency = [];
$compiled->includes = [];
@@ -72,12 +72,12 @@ abstract class RecompiledPlugin extends BasePlugin {
/**
* populate Compiled Object with compiled filepath
*
* @param Smarty_Template_Compiled $compiled compiled object
* @param Smarty_Internal_Template $_template template object
* @param Compiled $compiled compiled object
* @param Template $_template template object
*
* @return void
*/
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
$compiled->filepath = false;
$compiled->timestamp = false;
$compiled->exists = false;

View File

@@ -12,8 +12,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
/**
* Smarty Internal Plugin Resource Stream
@@ -28,12 +28,12 @@ class StreamPlugin extends RecompiledPlugin {
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
public function populate(Source $source, Template $_template = null) {
if (strpos($source->resource, '://') !== false) {
$source->filepath = $source->resource;
} else {
@@ -47,11 +47,11 @@ class StreamPlugin extends RecompiledPlugin {
/**
* Load template's source from stream into current template object
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string template source
*/
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
$t = '';
// the availability of the stream has already been checked in Smarty\Resource\Base::fetch()
$fp = fopen($source->filepath, 'r+');

View File

@@ -24,12 +24,12 @@ class StringEval extends Recompiled
/**
* populate Source Object with meta data from Resource
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty_Internal_Template $_template template object
* @param \Smarty\Template\Source $source source object
* @param \Smarty\Template $_template template object
*
* @return void
*/
public function populate(\Smarty_Template_Source $source, \Smarty_Internal_Template $_template = null)
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name);
$source->timestamp = $source->exists = true;
@@ -38,13 +38,13 @@ class StringEval extends Recompiled
/**
* Load template's source from $resource_name into current template object
*
* @uses decode() to decode base64 and urlencoded template_resources
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string template source
*@uses decode() to decode base64 and urlencoded template_resources
*
*/
public function getContent(\Smarty_Template_Source $source)
public function getContent(\Smarty\Template\Source $source)
{
return $this->decode($source->name);
}
@@ -86,11 +86,11 @@ class StringEval extends Recompiled
/**
* Determine basename for compiled filename
*
* @param \Smarty_Template_Source $source source object
* @param \Smarty\Template\Source $source source object
*
* @return string resource's basename
*/
public function getBasename(\Smarty_Template_Source $source)
public function getBasename(\Smarty\Template\Source $source)
{
return '';
}

View File

@@ -10,8 +10,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
/**
* Smarty Internal Plugin Resource String
@@ -21,17 +21,17 @@ use Smarty_Template_Source;
* @package Smarty
* @subpackage TemplateResources
*/
class StringPlugin extends Smarty\Resource\BasePlugin {
class StringPlugin extends BasePlugin {
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
public function populate(Source $source, Template $_template = null) {
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
$source->timestamp = $source->exists = true;
}
@@ -39,13 +39,13 @@ class StringPlugin extends Smarty\Resource\BasePlugin {
/**
* Load template's source from $resource_name into current template object
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string template source
* @uses decode() to decode base64 and urlencoded template_resources
*
*/
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
return $this->decode($source->name);
}
@@ -85,11 +85,11 @@ class StringPlugin extends Smarty\Resource\BasePlugin {
* Determine basename for compiled filename
* Always returns an empty string.
*
* @param Smarty_Template_Source $source source object
* @param Source $source source object
*
* @return string resource's basename
*/
public function getBasename(Smarty_Template_Source $source) {
public function getBasename(Source $source) {
return '';
}

View File

@@ -10,8 +10,8 @@
namespace Smarty\Resource;
use Smarty;
use Smarty_Internal_Template;
use Smarty_Template_Compiled;
use Smarty\Template;
use Smarty\Template\Compiled;
/**
* Smarty Resource Plugin
@@ -20,7 +20,7 @@ use Smarty_Template_Compiled;
* @package Smarty
* @subpackage TemplateResources
*/
abstract class UncompiledPlugin extends asePlugin {
abstract class UncompiledPlugin extends BasePlugin {
/**
* Flag that it's an uncompiled resource
@@ -39,10 +39,10 @@ abstract class UncompiledPlugin extends asePlugin {
/**
* populate compiled object with compiled filepath
*
* @param Smarty_Template_Compiled $compiled compiled object
* @param Smarty_Internal_Template $_template template object
* @param Compiled $compiled compiled object
* @param Template $_template template object
*/
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
$compiled->filepath = $_template->source->filepath;
$compiled->timestamp = $_template->source->timestamp;
$compiled->exists = $_template->source->exists;

View File

@@ -1,7 +1,7 @@
<?php
namespace Smarty\Runtime;
use Smarty_Internal_Template;
use Smarty\Template;
/**
* Runtime Extension Capture
@@ -50,12 +50,12 @@ class CaptureRuntime {
/**
* Open capture section
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
* @param string $buffer capture name
* @param string $assign variable name
* @param string $append variable name
*/
public function open(Smarty_Internal_Template $_template, $buffer, $assign, $append) {
public function open(Template $_template, $buffer, $assign, $append) {
if (!$this->isRegistered) {
$this->register($_template);
}
@@ -71,9 +71,9 @@ class CaptureRuntime {
/**
* Register callbacks in template class
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
*/
private function register(Smarty_Internal_Template $_template) {
private function register(Template $_template) {
$_template->startRenderCallbacks[] = [
$this,
'startRender',
@@ -89,9 +89,9 @@ class CaptureRuntime {
/**
* Start render callback
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
*/
public function startRender(Smarty_Internal_Template $_template) {
public function startRender(Template $_template) {
$this->countStack[] = $this->captureCount;
$this->captureCount = 0;
}
@@ -99,11 +99,11 @@ class CaptureRuntime {
/**
* Close capture section
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
*
* @throws \SmartyException
*/
public function close(Smarty_Internal_Template $_template) {
public function close(Template $_template) {
if ($this->captureCount) {
[$buffer, $assign, $append] = array_pop($this->captureStack);
$this->captureCount--;
@@ -122,23 +122,23 @@ class CaptureRuntime {
/**
* Error exception on not matching {capture}{/capture}
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
*
* @throws \SmartyException
*/
public function error(Smarty_Internal_Template $_template) {
public function error(Template $_template) {
throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'");
}
/**
* Return content of named capture buffer by key or as array
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
* @param string|null $name
*
* @return string|string[]|null
*/
public function getBuffer(Smarty_Internal_Template $_template, $name = null) {
public function getBuffer(Template $_template, $name = null) {
if (isset($name)) {
return $this->namedBuffer[$name] ?? null;
} else {
@@ -149,11 +149,11 @@ class CaptureRuntime {
/**
* End render callback
*
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template $_template
*
* @throws \SmartyException
*/
public function endRender(Smarty_Internal_Template $_template) {
public function endRender(Template $_template) {
if ($this->captureCount) {
$this->error($_template);
} else {

View File

@@ -1,7 +1,7 @@
<?php
namespace Smarty\Runtime;
use Smarty_Internal_Template;
use Smarty\Template;
/**
* Foreach Runtime Methods count(), init(), restore()
@@ -25,7 +25,7 @@ class ForeachRuntime {
* - init item and key variables, named foreach property data if required
* - count total if required
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param mixed $from values to loop over
* @param string $item variable name
* @param bool $needTotal flag if we need to count values
@@ -36,7 +36,7 @@ class ForeachRuntime {
* @return mixed $from
*/
public function init(
Smarty_Internal_Template $tpl,
Template $tpl,
$from,
$item,
$needTotal = false,
@@ -139,10 +139,10 @@ class ForeachRuntime {
*
* will be called by {break n} or {continue n} for the required number of levels
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param int $levels number of levels
*/
public function restore(Smarty_Internal_Template $tpl, $levels = 1) {
public function restore(Template $tpl, $levels = 1) {
while ($levels) {
$saveVars = array_pop($this->stack);
if (!empty($saveVars)) {

View File

@@ -1,8 +1,8 @@
<?php
namespace Smarty\Runtime;
use Smarty_Internal_Template;
use Smarty_Template_Source;
use Smarty\Template;
use Smarty\Template\Source;
use SmartyException;
/**
@@ -50,25 +50,25 @@ class InheritanceRuntime {
/**
* Array of template source objects
*
* @var Smarty_Template_Source[]
* @var Source[]
*/
public $sources = [];
/**
* Stack of source objects while executing block code
*
* @var Smarty_Template_Source[]
* @var Source[]
*/
public $sourceStack = [];
/**
* Initialize inheritance
*
* @param \Smarty_Internal_Template $tpl template object of caller
* @param \Smarty\Template $tpl template object of caller
* @param bool $initChild if true init for child template
* @param array $blockNames outer level block name
*/
public function init(Smarty_Internal_Template $tpl, $initChild, $blockNames = []) {
public function init(Template $tpl, $initChild, $blockNames = []) {
// if called while executing parent template it must be a sub-template with new inheritance root
if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) {
$tpl->inheritance = new InheritanceRuntime();
@@ -98,7 +98,7 @@ class InheritanceRuntime {
* End of child template(s)
* - if outer level is reached flush output buffer and switch to wait for parent template state
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param null|string $template optional name of inheritance parent template
* @param null|string $uid uid of inline template
* @param null|string $func function call name of inline template
@@ -106,7 +106,7 @@ class InheritanceRuntime {
* @throws \Exception
* @throws \SmartyException
*/
public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null) {
public function endChild(Template $tpl, $template = null, $uid = null, $func = null) {
--$this->inheritanceLevel;
if (!$this->inheritanceLevel) {
ob_end_clean();
@@ -135,14 +135,14 @@ class InheritanceRuntime {
* - if outer level {block} of child template ($state === 1) save it as child root block
* - otherwise process inheritance and render
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param $className
* @param string $name
* @param int|null $tplIndex index of outer level {block} if nested
*
* @throws \SmartyException
*/
public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null) {
public function instanceBlock(Template $tpl, $className, $name, $tplIndex = null) {
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex);
if (isset($this->childRoot[$name])) {
$block->child = $this->childRoot[$name];
@@ -161,14 +161,14 @@ class InheritanceRuntime {
/**
* Goto child block or render this
*
* @param Smarty_Internal_Template $tpl
* @param Template $tpl
* @param \Smarty\Block $block
* @param \Smarty\Block|null $parent
*
* @throws SmartyException
*/
public function process(
Smarty_Internal_Template $tpl,
Template $tpl,
\Smarty\Block $block,
\Smarty\Block $parent = null
) {
@@ -205,13 +205,13 @@ class InheritanceRuntime {
/**
* Render child on \$smarty.block.child
*
* @param Smarty_Internal_Template $tpl
* @param Template $tpl
* @param \Smarty\Block $block
*
* @return null|string block content
* @throws SmartyException
*/
public function callChild(Smarty_Internal_Template $tpl, \Smarty\Block $block) {
public function callChild(Template $tpl, \Smarty\Block $block) {
if (isset($block->child)) {
$this->process($tpl, $block->child, $block);
}
@@ -220,14 +220,14 @@ class InheritanceRuntime {
/**
* Render parent block on \$smarty.block.parent or {block append/prepend}
*
* @param Smarty_Internal_Template $tpl
* @param Template $tpl
* @param \Smarty\Block $block
* @param string $tag
*
* @return null|string block content
* @throws SmartyException
*/
public function callParent(Smarty_Internal_Template $tpl, \Smarty\Block $block, $tag) {
public function callParent(Template $tpl, \Smarty\Block $block, $tag) {
if (isset($block->parent)) {
$this->callBlock($block->parent, $tpl);
} else {
@@ -239,9 +239,9 @@ class InheritanceRuntime {
* render block
*
* @param \Smarty\Block $block
* @param Smarty_Internal_Template $tpl
* @param Template $tpl
*/
public function callBlock(\Smarty\Block $block, Smarty_Internal_Template $tpl) {
public function callBlock(\Smarty\Block $block, Template $tpl) {
$this->sourceStack[] = $tpl->source;
$tpl->source = $this->sources[$block->tplIndex];
$block->callBlock($tpl);

View File

@@ -1,7 +1,7 @@
<?php
namespace Smarty\Runtime;
use Smarty_Internal_Template;
use Smarty\Template;
/**
* {make_nocache} Runtime Methods save(), store()
@@ -16,12 +16,12 @@ class MakeNocacheRuntime {
* Save current variable value while rendering compiled template and inject nocache code to
* assign variable value in cached template
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param string $var variable name
*
* @throws \SmartyException
*/
public function save(Smarty_Internal_Template $tpl, $var) {
public function save(Template $tpl, $var) {
if (isset($tpl->tpl_vars[$var])) {
$export =
preg_replace('/^\\\\Smarty\\\\Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[$var], true));
@@ -37,11 +37,11 @@ class MakeNocacheRuntime {
/**
* Store variable value saved while rendering compiled template in cached template context
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param string $var variable name
* @param array $properties
*/
public function store(Smarty_Internal_Template $tpl, $var, $properties) {
public function store(Template $tpl, $var, $properties) {
// do not overwrite existing nocache variables
if (!isset($tpl->tpl_vars[$var]) || !$tpl->tpl_vars[$var]->nocache) {
$newVar = new \Smarty\Variable();

View File

@@ -1,8 +1,8 @@
<?php
namespace Smarty\Runtime;
use Smarty_Internal_Template;
use Smarty_Internal_TemplateBase;
use Smarty\Template;
use Smarty\TemplateBase;
/**
* TplFunction Runtime Methods callTemplateFunction
@@ -16,14 +16,14 @@ class TplFunctionRuntime {
/**
* Call template function
*
* @param \Smarty_Internal_Template $tpl template object
* @param \Smarty\Template $tpl template object
* @param string $name template function name
* @param array $params parameter array
* @param bool $nocache true if called nocache
*
* @throws \SmartyException
*/
public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache) {
public function callTemplateFunction(Template $tpl, $name, $params, $nocache) {
$funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null);
if (isset($funcParam)) {
if (!$tpl->caching || ($tpl->caching && $nocache)) {
@@ -55,14 +55,14 @@ class TplFunctionRuntime {
/**
* Register template functions defined by template
*
* @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $obj
* @param \Smarty|\Smarty\Template|\Smarty\TemplateBase $obj
* @param array $tplFunctions source information array of
* template functions defined
* in template
* @param bool $override if true replace existing
* functions with same name
*/
public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tplFunctions, $override = true) {
public function registerTplFunctions(TemplateBase $obj, $tplFunctions, $override = true) {
$obj->tplFunctions =
$override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions);
// make sure that the template functions are known in parent templates
@@ -77,12 +77,12 @@ class TplFunctionRuntime {
/**
* Return source parameter array for single or all template functions
*
* @param \Smarty_Internal_Template $tpl template object
* @param \Smarty\Template $tpl template object
* @param null|string $name template function name
*
* @return array|bool|mixed
*/
public function getTplFunction(Smarty_Internal_Template $tpl, $name = null) {
public function getTplFunction(Template $tpl, $name = null) {
if (isset($name)) {
return $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? false);
} else {
@@ -93,13 +93,13 @@ class TplFunctionRuntime {
/**
* Add template function to cache file for nocache calls
*
* @param Smarty_Internal_Template $tpl
* @param Template $tpl
* @param string $_name template function name
* @param string $_function PHP function name
*
* @return bool
*/
public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function) {
public function addTplFuncToCache(Template $tpl, $_name, $_function) {
$funcParam = $tpl->tplFunctions[$_name];
if (is_file($funcParam['compiled_filepath'])) {
// read compiled file
@@ -149,10 +149,10 @@ class TplFunctionRuntime {
/**
* Save current template variables on stack
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param string $name stack name
*/
public function saveTemplateVariables(Smarty_Internal_Template $tpl, $name) {
public function saveTemplateVariables(Template $tpl, $name) {
$tpl->_var_stack[] =
['tpl' => $tpl->tpl_vars, 'config' => $tpl->config_vars, 'name' => "_tplFunction_{$name}"];
}
@@ -160,10 +160,10 @@ class TplFunctionRuntime {
/**
* Restore saved variables into template objects
*
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
* @param string $name stack name
*/
public function restoreTemplateVariables(Smarty_Internal_Template $tpl, $name) {
public function restoreTemplateVariables(Template $tpl, $name) {
if (isset($tpl->_var_stack)) {
$vars = array_pop($tpl->_var_stack);
$tpl->tpl_vars = $vars['tpl'];

View File

@@ -41,7 +41,7 @@ use Smarty\Smarty\Runtime\TplFunctionRuntime;
/**
* This is the main Smarty class
*/
class Smarty extends \Smarty_Internal_TemplateBase
class Smarty extends \Smarty\TemplateBase
{
/**
* smarty version
@@ -597,7 +597,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
public function templateExists($resource_name)
{
// create source object
$source = \Smarty_Template_Source::load(null, $this, $resource_name);
$source = Template\Source::load(null, $this, $resource_name);
return $source->exists;
}
@@ -844,7 +844,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
*
* @return \Smarty_Internal_Template template object
* @return \Smarty\Template template object
* @throws \SmartyException
*/
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
@@ -864,17 +864,17 @@ class Smarty extends \Smarty_Internal_TemplateBase
}
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
$tpl = null;
if ($this->caching && isset(\Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) {
$tpl = $do_clone ? clone \Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] :
\Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
if ($this->caching && isset(\Smarty\Template::$isCacheTplObj[ $_templateId ])) {
$tpl = $do_clone ? clone \Smarty\Template::$isCacheTplObj[ $_templateId ] :
\Smarty\Template::$isCacheTplObj[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
} elseif (!$do_clone && isset(\Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
$tpl = clone \Smarty_Internal_Template::$tplObjCache[ $_templateId ];
} elseif (!$do_clone && isset(\Smarty\Template::$tplObjCache[ $_templateId ])) {
$tpl = clone \Smarty\Template::$tplObjCache[ $_templateId ];
$tpl->inheritance = null;
$tpl->tpl_vars = $tpl->config_vars = array();
} else {
/* @var \Smarty_Internal_Template $tpl */
/* @var \Smarty\Template $tpl */
$tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
$tpl->templateId = $_templateId;
}
@@ -906,7 +906,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*
* @return string
* @throws \SmartyException
@@ -916,7 +916,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
$cache_id = null,
$compile_id = null,
$caching = null,
\Smarty_Internal_Template $template = null
\Smarty\Template $template = null
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
@@ -985,8 +985,8 @@ class Smarty extends \Smarty_Internal_TemplateBase
*/
public function _clearTemplateCache()
{
\Smarty_Internal_Template::$isCacheTplObj = array();
\Smarty_Internal_Template::$tplObjCache = array();
\Smarty\Template::$isCacheTplObj = array();
\Smarty\Template::$tplObjCache = array();
}
/**
@@ -1294,7 +1294,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
if (isset($resource_name)) {
$_save_stat = $this->caching;
$this->caching = \Smarty\Smarty::CACHING_OFF;
/* @var Smarty_Internal_Template $tpl */
/* @var Template $tpl */
$tpl = $this->createTemplate($resource_name);
$this->caching = $_save_stat;
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
@@ -1472,7 +1472,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
$_smarty->_cache = array();
$_smarty->force_compile = $force_compile;
try {
/* @var Smarty_Internal_Template $_tpl */
/* @var Template $_tpl */
$_tpl = new $this->template_class($_file, $_smarty);
$_tpl->caching = self::CACHING_OFF;
$_tpl->source =
@@ -1506,14 +1506,14 @@ class Smarty extends \Smarty_Internal_TemplateBase
/**
* check client side cache
*
* @param \Smarty_Template_Cached $cached
* @param \Smarty_Internal_Template $_template
* @param \Smarty\Template\Cached $cached
* @param \Smarty\Template $_template
* @param string $content
*
* @throws \Exception
* @throws \SmartyException
*/
public function cacheModifiedCheck(\Smarty_Template_Cached $cached, \Smarty_Internal_Template $_template, $content)
public function cacheModifiedCheck(Template\Cached $cached, \Smarty\Template $_template, $content)
{
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
$_last_modified_date =
@@ -1569,12 +1569,12 @@ class Smarty extends \Smarty_Internal_TemplateBase
*
* @param string $type the type of filter ('pre','post','output') which shall run
* @param string $content the content which shall be processed by the filters
* @param Smarty_Internal_Template $template template object
* @param Template $template template object
*
* @throws SmartyException
* @return string the filtered content
*@throws SmartyException
*/
public function runFilter($type, $content, Smarty_Internal_Template $template)
public function runFilter($type, $content, Template $template)
{
// loop over registered filters of specified type
if (!empty($this->registered_filters[ $type ])) {

910
src/Template.php Normal file
View File

@@ -0,0 +1,910 @@
<?php
/**
* Smarty Internal Plugin Template
* This file contains the Smarty template engine
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
namespace Smarty;
use Smarty;
use Smarty\Runtime\InheritanceRuntime;
use Smarty\Template\Source;
use Smarty\Template\Cached;
use Smarty\Template\Compiled;
use Smarty\Template\Config;
use SmartyException;
/**
* Main class with template data structures and methods
*
* @property Compiled $compiled
* @property Cached $cached
* @property \Smarty\Compiler\Template $compiler
* @property mixed|\Smarty\Template\Cached registered_plugins
*/
#[\AllowDynamicProperties]
class Template extends TemplateBase {
/**
* Template object cache
*
* @var Template[]
*/
public static $tplObjCache = [];
/**
* Template object cache for Smarty::isCached() === true
*
* @var Template[]
*/
public static $isCacheTplObj = [];
/**
* Sub template Info Cache
* - index name
* - value use count
*
* @var int[]
*/
public static $subTplInfo = [];
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 2;
/**
* Source instance
*
* @var Source|Config
*/
public $source = null;
/**
* Inheritance runtime extension
*
* @var InheritanceRuntime
*/
public $inheritance = null;
/**
* Template resource
*
* @var string
*/
public $template_resource = null;
/**
* flag if compiled template is invalid and must be (re)compiled
*
* @var bool
*/
public $mustCompile = null;
/**
* Template Id
*
* @var null|string
*/
public $templateId = null;
/**
* Scope in which variables shall be assigned
*
* @var int
*/
public $scope = 0;
/**
* Flag which is set while rending a cache file
*
* @var bool
*/
public $isRenderingCache = false;
/**
* Callbacks called before rendering template
*
* @var callback[]
*/
public $startRenderCallbacks = [];
/**
* Callbacks called after rendering template
*
* @var callback[]
*/
public $endRenderCallbacks = [];
/**
* @var \Smarty\Compiler\CodeFrame
*/
private $codeFrameCompiler;
/**
* Create template data object
* Some of the global Smarty settings copied to template scope
* It load the required template resources and caching plugins
*
* @param string $template_resource template resource string
* @param Smarty $smarty Smarty instance
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty\Data $_parent back pointer to parent
* object with variables or
* null
* @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null
* @param bool|int|null $_caching use caching?
* @param int|null $_cache_lifetime cache life-time in
* seconds
* @param bool $_isConfig
*
* @throws \SmartyException
*/
public function __construct(
$template_resource,
Smarty $smarty,
\Smarty\Data $_parent = null,
$_cache_id = null,
$_compile_id = null,
$_caching = null,
$_cache_lifetime = null,
$_isConfig = false
) {
$this->smarty = $smarty;
// Smarty parameter
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
$this->caching = (int)($_caching === null ? $this->smarty->caching : $_caching);
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
$this->compile_check = (int)$smarty->compile_check;
$this->parent = $_parent;
// Template resource
$this->template_resource = $template_resource;
$this->source = $_isConfig ? Config::load($this) : Source::load($this);
parent::__construct();
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
$smarty->security_policy->registerCallBacks($this);
}
$this->codeFrameCompiler = new Smarty\Compiler\CodeFrame($this);
}
/**
* render template
*
* @param bool $no_output_filter if true do not run output filter
* @param null|bool $display true: display, false: fetch null: sub-template
*
* @return string
* @throws \Exception
* @throws \SmartyException
*/
public function render($no_output_filter = true, $display = null) {
if ($this->smarty->debugging) {
if (!isset($this->smarty->_debug)) {
$this->smarty->_debug = new \Smarty\Debug();
}
$this->smarty->_debug->start_template($this, $display);
}
// checks if template exists
if (!$this->source->exists) {
throw new SmartyException(
"Unable to load template '{$this->source->type}:{$this->source->name}'" .
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
);
}
// disable caching for evaluated code
if ($this->source->handler->recompiled) {
$this->caching = \Smarty\Smarty::CACHING_OFF;
}
// read from cache or render
if ($this->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT || $this->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED) {
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|| $this->cached->compile_id !== $this->compile_id
) {
$this->loadCached(true);
}
$this->cached->render($this, $no_output_filter);
} else {
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
$this->loadCompiled(true);
}
$this->compiled->render($this);
}
// display or fetch
if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) {
$this->smarty->cacheModifiedCheck(
$this->cached,
$this,
isset($content) ? $content : ob_get_clean()
);
} else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& !$no_output_filter && isset($this->smarty->registered_filters['output'])
) {
echo $this->smarty->runFilter('output', ob_get_clean(), $this);
} else {
echo ob_get_clean();
}
}
if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this);
// debug output
$this->smarty->_debug->display_debug($this, true);
}
return '';
} else {
if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this);
if ($this->smarty->debugging === 2 && $display === false) {
$this->smarty->_debug->display_debug($this, true);
}
}
if (
!$no_output_filter
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& isset($this->smarty->registered_filters['output'])
) {
return $this->smarty->runFilter('output', ob_get_clean(), $this);
}
// return cache content
return null;
}
}
/**
* Runtime function to render sub-template
*
* @param string $template template name
* @param mixed $cache_id cache id
* @param mixed $compile_id compile id
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $scope scope in which {include} should execute
* @param bool $forceTplCache cache template object
* @param string $uid file dependency uid
* @param string $content_func function name
*
* @throws \Exception
* @throws \SmartyException
*/
public function _subTemplateRender(
$template,
$cache_id,
$compile_id,
$caching,
$cache_lifetime,
$data,
$scope,
$forceTplCache,
$uid = null,
$content_func = null
) {
$tpl = clone $this;
$tpl->parent = $this;
$smarty = &$this->smarty;
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
// recursive call ?
if ((isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId()) !== $_templateId) {
// already in template cache?
if (isset(self::$tplObjCache[$_templateId])) {
// copy data from cached object
$cachedTpl = &self::$tplObjCache[$_templateId];
$tpl->templateId = $cachedTpl->templateId;
$tpl->template_resource = $cachedTpl->template_resource;
$tpl->cache_id = $cachedTpl->cache_id;
$tpl->compile_id = $cachedTpl->compile_id;
$tpl->source = $cachedTpl->source;
if (isset($cachedTpl->compiled)) {
$tpl->compiled = $cachedTpl->compiled;
} else {
unset($tpl->compiled);
}
if ($caching !== 9999 && isset($cachedTpl->cached)) {
$tpl->cached = $cachedTpl->cached;
} else {
unset($tpl->cached);
}
} else {
$tpl->templateId = $_templateId;
$tpl->template_resource = $template;
$tpl->cache_id = $cache_id;
$tpl->compile_id = $compile_id;
if (isset($uid)) {
// for inline templates we can get all resource information from file dependency
[$filepath, $timestamp, $type] = $tpl->compiled->file_dependency[$uid];
$tpl->source = new Source($smarty, $filepath, $type, $filepath);
$tpl->source->filepath = $filepath;
$tpl->source->timestamp = $timestamp;
$tpl->source->exists = true;
$tpl->source->uid = $uid;
} else {
$tpl->source = Source::load($tpl);
unset($tpl->compiled);
}
if ($caching !== 9999) {
unset($tpl->cached);
}
}
} else {
// on recursive calls force caching
$forceTplCache = true;
}
$tpl->caching = $caching;
$tpl->cache_lifetime = $cache_lifetime;
// set template scope
$tpl->scope = $scope;
if (!isset(self::$tplObjCache[$tpl->templateId]) && !$tpl->source->handler->recompiled) {
// check if template object should be cached
if ($forceTplCache || (isset(self::$subTplInfo[$tpl->template_resource])
&& self::$subTplInfo[$tpl->template_resource] > 1)
|| ($tpl->_isSubTpl() && isset(self::$tplObjCache[$tpl->parent->templateId]))
) {
self::$tplObjCache[$tpl->templateId] = $tpl;
}
}
if (!empty($data)) {
// set up variable values
foreach ($data as $_key => $_val) {
$tpl->tpl_vars[$_key] = new \Smarty\Variable($_val, $this->isRenderingCache);
}
}
if ($tpl->caching === 9999) {
if (!isset($tpl->compiled)) {
$tpl->loadCompiled(true);
}
if ($tpl->compiled->has_nocache_code) {
$this->cached->hashes[$tpl->compiled->nocache_hash] = true;
}
}
$tpl->_cache = [];
if (isset($uid)) {
if ($smarty->debugging) {
if (!isset($smarty->_debug)) {
$smarty->_debug = new \Smarty\Debug();
}
$smarty->_debug->start_template($tpl);
$smarty->_debug->start_render($tpl);
}
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
if ($smarty->debugging) {
$smarty->_debug->end_template($tpl);
$smarty->_debug->end_render($tpl);
}
} else {
if (isset($tpl->compiled)) {
$tpl->compiled->render($tpl);
} else {
$tpl->render();
}
}
}
/**
* Get called sub-templates and save call count
*/
public function _subTemplateRegister() {
foreach ($this->compiled->includes as $name => $count) {
if (isset(self::$subTplInfo[$name])) {
self::$subTplInfo[$name] += $count;
} else {
self::$subTplInfo[$name] = $count;
}
}
}
/**
* Check if this is a sub template
*
* @return bool true is sub template
*/
public function _isSubTpl() {
return isset($this->parent) && $this->parent->_isTplObj();
}
/**
* Assign variable in scope
*
* @param string $varName variable name
* @param mixed $value value
* @param bool $nocache nocache flag
* @param int $scope scope into which variable shall be assigned
*/
public function _assignInScope($varName, $value, $nocache = false, $scope = 0) {
if (isset($this->tpl_vars[$varName])) {
$this->tpl_vars[$varName] = clone $this->tpl_vars[$varName];
$this->tpl_vars[$varName]->value = $value;
if ($nocache || $this->isRenderingCache) {
$this->tpl_vars[$varName]->nocache = true;
}
} else {
$this->tpl_vars[$varName] = new \Smarty\Variable($value, $nocache || $this->isRenderingCache);
}
if ($scope >= 0) {
if ($scope > 0 || $this->scope > 0) {
$this->_updateScope($varName, $scope);
}
}
}
/**
* This function is executed automatically when a compiled or cached template file is included
* - Decode saved properties from compiled template and cache files
* - Check if compiled or cache file is valid
*
* @param \Smarty_Internal_Template $tpl
* @param array $properties special template properties
* @param bool $cache flag if called from cache file
*
* @return bool flag if compiled or cache file is valid
* @throws \SmartyException
*/
public function _decodeProperties(Template $tpl, $properties, $cache = false) {
// on cache resources other than file check version stored in cache code
if (!isset($properties['version']) || \Smarty\Smarty::SMARTY_VERSION !== $properties['version']) {
if ($cache) {
$tpl->smarty->clearAllCache();
} else {
$tpl->smarty->clearCompiledTemplate();
}
return false;
}
$is_valid = true;
if (!empty($properties['file_dependency'])
&& ((!$cache && $tpl->compile_check) || $tpl->compile_check === \Smarty\Smarty::COMPILECHECK_ON)
) {
// check file dependencies at compiled code
foreach ($properties['file_dependency'] as $_file_to_check) {
if ($_file_to_check[2] === 'file' || $_file_to_check[2] === 'php') {
if ($tpl->source->filepath === $_file_to_check[0]) {
// do not recheck current template
continue;
//$mtime = $tpl->source->getTimeStamp();
} else {
// file and php types can be checked without loading the respective resource handlers
$mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
}
} else {
$handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[2]);
if ($handler->checkTimestamps()) {
$source = Source::load($tpl, $tpl->smarty, $_file_to_check[0]);
$mtime = $source->getTimeStamp();
} else {
continue;
}
}
if ($mtime === false || $mtime > $_file_to_check[1]) {
$is_valid = false;
break;
}
}
}
if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($tpl->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0
&& (time() > ($tpl->cached->timestamp + $properties['cache_lifetime']))
) {
$is_valid = false;
}
$tpl->cached->cache_lifetime = $properties['cache_lifetime'];
$tpl->cached->valid = $is_valid;
$resource = $tpl->cached;
} else {
$tpl->mustCompile = !$is_valid;
$resource = $tpl->compiled;
$resource->includes = isset($properties['includes']) ? $properties['includes'] : [];
}
if ($is_valid) {
$resource->unifunc = $properties['unifunc'];
$resource->has_nocache_code = $properties['has_nocache_code'];
$resource->file_dependency = $properties['file_dependency'];
}
return $is_valid && !function_exists($properties['unifunc']);
}
/**
* Compiles the template
* If the template is not evaluated the compiled template is saved on disk
*
* @throws \Exception
*/
public function compileTemplateSource() {
return $this->compiled->compileTemplateSource($this);
}
/**
* Writes the content to cache resource
*
* @param string $content
*
* @return bool
*/
public function writeCachedContent($content) {
if ($this->source->handler->recompiled || !$this->caching
) {
// don't write cache file
return false;
}
if (!isset($this->cached)) {
$this->loadCached();
}
$codeframe = $this->createCodeFrame($content, '', true);
return $this->cached->writeCache($this, $codeframe);
}
/**
* Get unique template id
*
* @return string
* @throws \SmartyException
*/
public function _getTemplateId() {
return $this->templateId ?? $this->templateId =
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
}
/**
* runtime error not matching capture tags
*
* @throws \SmartyException
*/
public function capture_error() {
throw new SmartyException("Not matching {capture} open/close in '{$this->template_resource}'");
}
/**
* Load compiled object
*
* @param bool $force force new compiled object
*/
public function loadCompiled($force = false) {
if ($force || !isset($this->compiled)) {
$this->compiled = Compiled::load($this);
}
}
/**
* Load cached object
*
* @param bool $force force new cached object
*/
public function loadCached($force = false) {
if ($force || !isset($this->cached)) {
$this->cached = Cached::load($this);
}
}
/**
* Load inheritance object
*/
public function _loadInheritance() {
if (!isset($this->inheritance)) {
$this->inheritance = new InheritanceRuntime();
}
}
/**
* Unload inheritance object
*/
public function _cleanUp() {
$this->startRenderCallbacks = [];
$this->endRenderCallbacks = [];
$this->inheritance = null;
}
/**
* Load compiler object
*
* @throws \SmartyException
*/
public function loadCompiler() {
$this->compiler =
new $this->source->compiler_class(
$this->source->template_lexer_class,
$this->source->template_parser_class,
$this->smarty
);
}
/**
* Create code frame for compiled and cached templates
*
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty\Compiler\Template $compiler
*
* @return string
*/
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) {
return $this->codeFrameCompiler->create($content, $functions, $cache, $compiler);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @return mixed
*/
public function __call($name, $args) {
// method of Smarty object?
if (method_exists($this->smarty, $name)) {
return call_user_func_array([$this->smarty, $name], $args);
}
// parent
return parent::__call($name, $args);
}
/**
* get Smarty property in template context
*
* @param string $property_name property name
*
* @return mixed|Cached
* @throws SmartyException
*/
public function __get($property_name) {
switch ($property_name) {
case 'compiled':
$this->loadCompiled();
return $this->compiled;
case 'cached':
$this->loadCached();
return $this->cached;
case 'compiler':
$this->loadCompiler();
return $this->compiler;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
return $this->smarty->$property_name;
}
}
throw new SmartyException("template property '$property_name' does not exist.");
}
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value) {
switch ($property_name) {
case 'compiled':
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new SmartyException("invalid template property '$property_name'.");
}
/**
* Template data object destructor
*/
public function __destruct() {
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
$this->cached->handler->releaseLock($this->smarty, $this->cached);
}
}
/**
* load config variables into template object
*
* @param \Smarty_Internal_Template $tpl
* @param array $new_config_vars
*/
public function _loadConfigVars($new_config_vars) {
$this->_assignConfigVars($this->parent->config_vars, $new_config_vars);
$tagScope = $this->source->scope;
if ($tagScope >= 0) {
if ($tagScope === \Smarty\Smarty::SCOPE_LOCAL) {
$this->_updateConfigVarStack($new_config_vars);
$tagScope = 0;
if (!$this->scope) {
return;
}
}
if ($this->parent->_isTplObj() && ($tagScope || $this->parent->scope)) {
$mergedScope = $tagScope | $this->scope;
if ($mergedScope) {
// update scopes
/* @var \Smarty_Internal_Template|\Smarty|Data $ptr */
foreach ($this->parent->_getAffectedScopes($mergedScope) as $ptr) {
$this->_assignConfigVars($ptr->config_vars, $new_config_vars);
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
$this->_updateConfigVarStack($new_config_vars);
}
}
}
}
}
}
/**
* Assign all config variables in given scope
*
* @param array $config_vars config variables in scope
* @param array $new_config_vars loaded config variables
*/
private function _assignConfigVars(&$config_vars, $new_config_vars) {
// copy global config vars
foreach ($new_config_vars['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($config_vars[$variable])) {
$config_vars[$variable] = $value;
} else {
$config_vars[$variable] = array_merge((array)$config_vars[$variable], (array)$value);
}
}
// scan sections
$sections = $this->source->config_sections;
if (!empty($sections)) {
foreach ((array)$sections as $tpl_section) {
if (isset($new_config_vars['sections'][$tpl_section])) {
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($config_vars[$variable])) {
$config_vars[$variable] = $value;
} else {
$config_vars[$variable] = array_merge((array)$config_vars[$variable], (array)$value);
}
}
}
}
}
}
/**
* Update config variables in template local variable stack
*
* @param array $config_vars
*/
private function _updateConfigVarStack($config_vars) {
$i = 0;
while (isset($this->_var_stack[$i])) {
$this->_assignConfigVars($this->_var_stack[$i]['config'], $config_vars);
$i++;
}
}
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
* configuration
*
* @return bool
* @throws \SmartyException
*/
public function mustCompile() {
if (!$this->source->exists) {
if ($this->_isSubTpl()) {
$parent_resource = " in '{$this->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->handler->uncompiled &&
($this->smarty->force_compile || $this->source->handler->recompiled ||
!$this->compiled->exists || ($this->compile_check &&
$this->compiled->getTimeStamp() <
$this->source->getTimeStamp())));
}
return $this->mustCompile;
}
/**
* Update new assigned template or config variable in other effected scopes
*
* @param string|null $varName variable name
* @param int $tagScope tag scope to which bubble up variable value
*/
protected function _updateScope($varName, $tagScope = 0) {
if ($tagScope) {
$this->_updateVarStack($this, $varName);
$tagScope = $tagScope & ~\Smarty\Smarty::SCOPE_LOCAL;
if (!$this->scope && !$tagScope) {
return;
}
}
$mergedScope = $tagScope | $this->scope;
if ($mergedScope) {
if ($mergedScope & \Smarty\Smarty::SCOPE_GLOBAL && $varName) {
\Smarty\Smarty::$global_tpl_vars[$varName] = $this->tpl_vars[$varName];
}
// update scopes
foreach ($this->_getAffectedScopes($mergedScope) as $ptr) {
$this->_updateVariableInOtherScope($ptr->tpl_vars, $varName);
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
$this->_updateVarStack($ptr, $varName);
}
}
}
}
/**
* Get array of objects which needs to be updated by given scope value
*
* @param int $mergedScope merged tag and template scope to which bubble up variable value
*
* @return array
*/
private function _getAffectedScopes($mergedScope) {
$_stack = [];
$ptr = $this->parent;
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$mergedScope = $mergedScope & ~\Smarty\Smarty::SCOPE_PARENT;
if (!$mergedScope) {
// only parent was set, we are done
return $_stack;
}
$ptr = $ptr->parent;
}
while (isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$ptr = $ptr->parent;
}
if ($mergedScope & \Smarty\Smarty::SCOPE_SMARTY) {
if (isset($this->smarty)) {
$_stack[] = $this->smarty;
}
} elseif ($mergedScope & \Smarty\Smarty::SCOPE_ROOT) {
while (isset($ptr)) {
if (!$ptr->_isTplObj()) {
$_stack[] = $ptr;
break;
}
$ptr = $ptr->parent;
}
}
return $_stack;
}
/**
* Update variable in other scope
*
* @param array $tpl_vars template variable array
* @param string $varName variable name
*/
private function _updateVariableInOtherScope(&$tpl_vars, $varName) {
if (!isset($tpl_vars[$varName])) {
$tpl_vars[$varName] = clone $this->tpl_vars[$varName];
} else {
$tpl_vars[$varName] = clone $tpl_vars[$varName];
$tpl_vars[$varName]->value = $this->tpl_vars[$varName]->value;
}
}
/**
* Update variable in template local variable stack
*
* @param \Smarty_Internal_Template $tpl
* @param string|null $varName variable name or null for config variables
*/
private function _updateVarStack(Template $tpl, $varName) {
$i = 0;
while (isset($tpl->_var_stack[$i])) {
$this->_updateVariableInOtherScope($tpl->_var_stack[$i]['tpl'], $varName);
$i++;
}
}
}

379
src/Template/Cached.php Normal file
View File

@@ -0,0 +1,379 @@
<?php
namespace Smarty\Template;
use Smarty\Template;
use Smarty\Template\ResourceBase;
use Smarty\Template\Source;
/**
* Smarty Resource Data Object
* Cache Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Cached extends ResourceBase {
/**
* Cache Is Valid
*
* @var boolean
*/
public $valid = null;
/**
* CacheResource Handler
*
* @var \Smarty\Cacheresource\Base
*/
public $handler = null;
/**
* Template Cache Id (\Smarty\Template::$cache_id)
*
* @var string
*/
public $cache_id = null;
/**
* saved cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 0;
/**
* Id for cache locking
*
* @var string
*/
public $lock_id = null;
/**
* flag that cache is locked by this instance
*
* @var bool
*/
public $is_locked = false;
/**
* Source Object
*
* @var Source
*/
public $source = null;
/**
* Nocache hash codes of processed compiled templates
*
* @var array
*/
public $hashes = [];
/**
* Flag if this is a cache resource
*
* @var bool
*/
public $isCache = true;
/**
* create Cached Object container
*
* @param Template $_template template object
*
* @throws \SmartyException
*/
public function __construct(Template $_template) {
$this->compile_id = $_template->compile_id;
$this->cache_id = $_template->cache_id;
$this->source = $_template->source;
$this->handler = \Smarty\Cacheresource\Base::load($_template->smarty);
}
/**
* @param Template $_template
*
* @return Cached
*/
public static function load(Template $_template) {
$_template->cached = new Cached($_template);
$_template->cached->handler->populate($_template->cached, $_template);
// caching enabled ?
if (!$_template->caching || $_template->source->handler->recompiled
) {
$_template->cached->valid = false;
}
return $_template->cached;
}
/**
* Render cache template
*
* @param \Smarty\Template $_template
* @param bool $no_output_filter
*
* @throws \Exception
*/
public function render(Template $_template, $no_output_filter = true) {
if ($this->isCached($_template)) {
if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new \Smarty\Debug();
}
$_template->smarty->_debug->start_cache($_template);
}
if (!$this->processed) {
$this->process($_template);
}
$this->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
return;
} else {
$this->updateCache($_template, $no_output_filter);
}
}
/**
* Check if cache is valid, lock cache if required
*
* @param \Smarty\Template $_template
*
* @return bool flag true if cache is valid
*/
public function isCached(Template $_template) {
if ($this->valid !== null) {
return $this->valid;
}
while (true) {
while (true) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$this->valid = false;
} else {
$this->valid = true;
}
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT
&& $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
) {
// lifetime expired
$this->valid = false;
}
if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON
&& $_template->source->getTimeStamp() > $this->timestamp
) {
$this->valid = false;
}
if ($this->valid || !$_template->smarty->cache_locking) {
break;
}
if (!$this->handler->locked($_template->smarty, $this)) {
$this->handler->acquireLock($_template->smarty, $this);
break 2;
}
$this->handler->populate($this, $_template);
}
if ($this->valid) {
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_cache($_template);
}
if ($this->handler->process($_template, $this) === false) {
$this->valid = false;
} else {
$this->processed = true;
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
} else {
$this->is_locked = true;
continue;
}
} else {
return $this->valid;
}
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED
&& $_template->cached->cache_lifetime >= 0
&& (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
) {
$this->valid = false;
}
if ($_template->smarty->cache_locking) {
if (!$this->valid) {
$this->handler->acquireLock($_template->smarty, $this);
} elseif ($this->is_locked) {
$this->handler->releaseLock($_template->smarty, $this);
}
}
return $this->valid;
}
return $this->valid;
}
/**
* Process cached template
*
* @param Template $_template template object
* @param bool $update flag if called because cache update
*/
public function process(Template $_template, $update = false) {
if ($this->handler->process($_template, $this, $update) === false) {
$this->valid = false;
}
if ($this->valid) {
$this->processed = true;
} else {
$this->processed = false;
}
}
/**
* Read cache content from handler
*
* @param Template $_template template object
*
* @return string|false content
*/
public function readCache(Template $_template) {
if (!$_template->source->handler->recompiled) {
return $this->handler->retrieveCachedContent($_template);
}
return false;
}
/**
* Write this cache object to handler
*
* @param string $content content to cache
*
* @return bool success
*/
public function writeCache(Template $_template, $content) {
if (!$_template->source->handler->recompiled) {
if ($this->handler->storeCachedContent($_template, $content)) {
$this->content = null;
$this->timestamp = time();
$this->exists = true;
$this->valid = true;
$this->cache_lifetime = $_template->cache_lifetime;
$this->processed = false;
if ($_template->smarty->cache_locking) {
$this->handler->releaseLock($_template->smarty, $this);
}
return true;
}
$this->content = null;
$this->timestamp = false;
$this->exists = false;
$this->valid = false;
$this->processed = false;
}
return false;
}
/**
* Cache was invalid , so render from compiled and write to cache
*
* @param Template $_template
* @param bool $no_output_filter
*
* @throws \SmartyException
*/
public function updateCache(Template $_template, $no_output_filter) {
ob_start();
if (!isset($_template->compiled)) {
$_template->loadCompiled();
}
$_template->compiled->render($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_cache($_template);
}
$this->removeNoCacheHash($_template, $no_output_filter);
$compile_check = (int)$_template->compile_check;
$_template->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
if ($_template->_isSubTpl()) {
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
}
if (!$_template->cached->processed) {
$_template->cached->process($_template, true);
}
$_template->compile_check = $compile_check;
$this->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
}
/**
* Sanitize content and write it to cache resource
*
* @param Template $_template
* @param bool $no_output_filter
*
* @throws \SmartyException
*/
private function removeNoCacheHash(Template $_template, $no_output_filter) {
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
$content = ob_get_clean();
$hash_array = $this->hashes;
$hash_array[$_template->compiled->nocache_hash] = true;
$hash_array = array_keys($hash_array);
$nocache_hash = '(' . implode('|', $hash_array) . ')';
$_template->cached->has_nocache_code = false;
// get text between non-cached items
$cache_split =
preg_split(
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content
);
// get non-cached items
preg_match_all(
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content,
$cache_parts
);
$content = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
if (preg_match($php_pattern, $curr_split)) {
// escape PHP tags in template content
$php_split = preg_split(
$php_pattern,
$curr_split
);
preg_match_all(
$php_pattern,
$curr_split,
$php_parts
);
foreach ($php_split as $idx_php => $curr_php) {
$content .= $curr_php;
if (isset($php_parts[0][$idx_php])) {
$content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
}
}
} else {
$content .= $curr_split;
}
if (isset($cache_parts[0][$curr_idx])) {
$_template->cached->has_nocache_code = true;
$content .= $cache_parts[2][$curr_idx];
}
}
if (
!$no_output_filter
&& !$_template->cached->has_nocache_code
&& isset($_template->smarty->registered_filters['output'])
) {
$content = $_template->smarty->runFilter('output', $content, $_template);
}
// write cache file content
$_template->writeCachedContent($content);
}
}

253
src/Template/Compiled.php Normal file
View File

@@ -0,0 +1,253 @@
<?php
namespace Smarty\Template;
use Smarty\Template;
/**
* Smarty Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @property string $content compiled content
*/
class Compiled extends ResourceBase {
/**
* nocache hash
*
* @var string|null
*/
public $nocache_hash = null;
/**
* get a Compiled Object of this source
*
* @param Template $_template template object
*
* @return Compiled compiled object
*/
public static function load($_template) {
$compiled = new Compiled();
if ($_template->source->handler->hasCompiledHandler) {
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else {
$compiled->populateCompiledFilepath($_template);
}
return $compiled;
}
/**
* populate Compiled Object with compiled filepath
*
* @param Template $_template template object
**/
public function populateCompiledFilepath(Template $_template) {
$source = &$_template->source;
$smarty = &$_template->smarty;
$this->filepath = $smarty->getCompileDir();
if (isset($_template->compile_id)) {
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
$this->filepath .= $source->uid[0] . $source->uid[1] . DIRECTORY_SEPARATOR . $source->uid[2] .
$source->uid[3] . DIRECTORY_SEPARATOR . $source->uid[4] . $source->uid[5] .
DIRECTORY_SEPARATOR;
}
$this->filepath .= $source->uid . '_';
if ($source->isConfig) {
$this->filepath .= (int)$smarty->config_read_hidden + (int)$smarty->config_booleanize * 2 +
(int)$smarty->config_overwrite * 4;
} else {
$this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 +
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
(int)$smarty->extends_recursion * 4 : 0);
}
$this->filepath .= '.' . $source->type;
$basename = $source->handler->getBasename($source);
if (!empty($basename)) {
$this->filepath .= '.' . $basename;
}
if ($_template->caching) {
$this->filepath .= '.cache';
}
$this->filepath .= '.php';
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = filemtime($this->filepath);
}
}
/**
* render compiled template code
*
* @param Template $_template
*
* @return string
* @throws Exception
*/
public function render(Template $_template) {
// checks if template exists
if (!$_template->source->exists) {
$type = $_template->source->isConfig ? 'config' : 'template';
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
}
if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new \Smarty\Debug();
}
$_template->smarty->_debug->start_render($_template);
}
if (!$this->processed) {
$this->process($_template);
}
if (isset($_template->cached)) {
$_template->cached->file_dependency =
array_merge($_template->cached->file_dependency, $this->file_dependency);
}
if ($_template->source->handler->uncompiled) {
$_template->source->handler->renderUncompiled($_template->source, $_template);
} else {
$this->getRenderedTemplateCode($_template);
}
if ($_template->caching && $this->has_nocache_code) {
$_template->cached->hashes[$this->nocache_hash] = true;
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_render($_template);
}
}
/**
* load compiled template or compile from source
*
* @param Template $_smarty_tpl do not change variable name, is used by compiled template
*
* @throws Exception
*/
public function process(Template $_smarty_tpl) {
$source = &$_smarty_tpl->source;
$smarty = &$_smarty_tpl->smarty;
if ($source->handler->recompiled) {
$source->handler->process($_smarty_tpl);
} elseif (!$source->handler->uncompiled) {
if (!$this->exists || $smarty->force_compile
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
) {
$this->compileTemplateSource($_smarty_tpl);
$compileCheck = $_smarty_tpl->compile_check;
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
$this->loadCompiledTemplate($_smarty_tpl);
$_smarty_tpl->compile_check = $compileCheck;
} else {
$_smarty_tpl->mustCompile = true;
@include $this->filepath;
if ($_smarty_tpl->mustCompile) {
$this->compileTemplateSource($_smarty_tpl);
$compileCheck = $_smarty_tpl->compile_check;
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
$this->loadCompiledTemplate($_smarty_tpl);
$_smarty_tpl->compile_check = $compileCheck;
}
}
$_smarty_tpl->_subTemplateRegister();
$this->processed = true;
}
}
/**
* compile template from source
*
* @param Template $_template
*
* @throws Exception
*/
public function compileTemplateSource(Template $_template) {
$this->file_dependency = [];
$this->includes = [];
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
$saved_timestamp = $this->getTimeStamp();
touch($this->filepath);
}
// compile locking
try {
// call compiler
$_template->loadCompiler();
$this->write($_template, $_template->compiler->compileTemplate($_template));
} catch (Exception $e) {
// restore old timestamp in case of error
if ($saved_timestamp && is_file($this->filepath)) {
touch($this->filepath, $saved_timestamp);
}
unset($_template->compiler);
throw $e;
}
// release compiler object to free memory
unset($_template->compiler);
}
/**
* Write compiled code by handler
*
* @param Template $_template template object
* @param string $code compiled code
*
* @return bool success
* @throws \SmartyException
*/
public function write(Template $_template, $code) {
if (!$_template->source->handler->recompiled) {
if ($_template->smarty->writeFile($this->filepath, $code) === true) {
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = filemtime($this->filepath);
return true;
}
}
return false;
}
return true;
}
/**
* Read compiled content from handler
*
* @param Template $_template template object
*
* @return string content
*/
public function read(Template $_template) {
if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath);
}
return isset($this->content) ? $this->content : false;
}
/**
* Load fresh compiled template by including the PHP file
* HHVM requires a work around because of a PHP incompatibility
*
* @param \Smarty\Template $_smarty_tpl do not change variable name, is used by compiled template
*/
private function loadCompiledTemplate(Template $_smarty_tpl) {
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
if (defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($this->filepath));
} else {
include $this->filepath;
}
}
}

97
src/Template/Config.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
namespace Smarty\Template;
use Smarty;
use Smarty\Template;
use SmartyException;
/**
* Smarty Config Resource Data Object
* Meta Data Container for Config Files
*
* @author Uwe Tews
*/
class Config extends Source {
/**
* array of section names, single section or null
*
* @var null|string|array
*/
public $config_sections = null;
/**
* scope into which the config variables shall be loaded
*
* @var int
*/
public $scope = 0;
/**
* Flag that source is a config file
*
* @var bool
*/
public $isConfig = true;
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty\Compiler\ConfigFile';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Configfileparser';
/**
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Config Source Object
* @throws SmartyException
*/
public static function load(
Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
static $_incompatible_resources = ['extends' => true, 'php' => true];
if ($_template) {
$smarty = $_template->smarty;
$template_resource = $_template->template_resource;
}
if (empty($template_resource)) {
throw new SmartyException('Source: Missing name');
}
// parse resource_name, load resource handler
[$name, $type] = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[$type])) {
throw new SmartyException("Unable to use resource '{$type}' for config");
}
$source = new Config($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template);
if (!$source->exists && isset($smarty->default_config_handler_func)) {
$source->_getDefaultTemplate($smarty->default_config_handler_func);
$source->handler->populate($source, $_template);
}
return $source;
}
}

View File

@@ -0,0 +1,154 @@
<?php
namespace Smarty\Template;
use Smarty\Template;
/**
* Smarty Template Resource Base Object
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
abstract class ResourceBase {
/**
* Compiled Filepath
*
* @var string
*/
public $filepath = null;
/**
* Compiled Timestamp
*
* @var integer|bool
*/
public $timestamp = false;
/**
* Compiled Existence
*
* @var boolean
*/
public $exists = false;
/**
* Template Compile Id (\Smarty\Template::$compile_id)
*
* @var string
*/
public $compile_id = null;
/**
* Compiled Content Loaded
*
* @var boolean
*/
public $processed = false;
/**
* unique function name for compiled template code
*
* @var string
*/
public $unifunc = '';
/**
* flag if template does contain nocache code sections
*
* @var bool
*/
public $has_nocache_code = false;
/**
* resource file dependency
*
* @var array
*/
public $file_dependency = [];
/**
* Content buffer
*
* @var string
*/
public $content = null;
/**
* Included sub templates
* - index name
* - value use count
*
* @var int[]
*/
public $includes = [];
/**
* Flag if this is a cache resource
*
* @var bool
*/
public $isCache = false;
/**
* Process resource
*
* @param Template $_template template object
*/
abstract public function process(Template $_template);
/**
* get rendered template content by calling compiled or cached template code
*
* @param \Smarty\Template $_template
* @param string $unifunc function with template code
*
* @throws \Exception
*/
public function getRenderedTemplateCode(Template $_template, $unifunc = null) {
$smarty = &$_template->smarty;
$_template->isRenderingCache = $this->isCache;
$level = ob_get_level();
try {
if (!isset($unifunc)) {
$unifunc = $this->unifunc;
}
if (empty($unifunc) || !function_exists($unifunc)) {
throw new \SmartyException("Invalid compiled template for '{$_template->template_resource}'");
}
if ($_template->startRenderCallbacks) {
foreach ($_template->startRenderCallbacks as $callback) {
call_user_func($callback, $_template);
}
}
$unifunc($_template);
foreach ($_template->endRenderCallbacks as $callback) {
call_user_func($callback, $_template);
}
$_template->isRenderingCache = false;
} catch (\Exception $e) {
$_template->isRenderingCache = false;
while (ob_get_level() > $level) {
ob_end_clean();
}
if (isset($smarty->security_policy)) {
$smarty->security_policy->endTemplate();
}
throw $e;
}
}
/**
* Get compiled time stamp
*
* @return int
*/
public function getTimeStamp() {
if ($this->exists && !$this->timestamp) {
$this->timestamp = filemtime($this->filepath);
}
return $this->timestamp;
}
}

253
src/Template/Source.php Normal file
View File

@@ -0,0 +1,253 @@
<?php
namespace Smarty\Template;
use Smarty;
use Smarty\Template;
use SmartyException;
/**
* Smarty Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Source {
/**
* Unique Template ID
*
* @var string
*/
public $uid = null;
/**
* Template Resource (Smarty_Internal_Template::$template_resource)
*
* @var string
*/
public $resource = null;
/**
* Resource Type
*
* @var string
*/
public $type = null;
/**
* Resource Name
*
* @var string
*/
public $name = null;
/**
* Source Filepath
*
* @var string
*/
public $filepath = null;
/**
* Source Timestamp
*
* @var integer
*/
public $timestamp = null;
/**
* Source Existence
*
* @var boolean
*/
public $exists = false;
/**
* Source File Base name
*
* @var string
*/
public $basename = null;
/**
* The Components an extended template is made of
*
* @var \Smarty_Template_Source[]
*/
public $components = null;
/**
* Resource Handler
*
* @var \Smarty\Resource\BasePlugin
*/
public $handler = null;
/**
* Smarty instance
*
* @var Smarty
*/
public $smarty = null;
/**
* Resource is source
*
* @var bool
*/
public $isConfig = false;
/**
* Template source content eventually set by default handler
*
* @var string
*/
public $content = null;
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty\Compiler\Template';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* create Source Object container
*
* @param Smarty $smarty Smarty instance this source object belongs to
* @param string $resource full template_resource
* @param string $type type of resource
* @param string $name resource name
*
* @throws \SmartyException
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
*/
public function __construct(Smarty $smarty, $resource, $type, $name) {
$this->handler = Smarty\Resource\BasePlugin::load($smarty, $type);
$this->smarty = $smarty;
$this->resource = $resource;
$this->type = $type;
$this->name = $name;
}
/**
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Source Source Object
* @throws SmartyException
*/
public static function load(
Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
if ($_template) {
$smarty = $_template->smarty;
$template_resource = $_template->template_resource;
}
if (empty($template_resource)) {
throw new SmartyException('Source: Missing name');
}
// parse resource_name, load resource handler, identify unique resource name
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
$type = $match[1];
$name = $match[2];
} else {
// no resource given, use default
// or single character before the colon is not a resource type, but part of the filepath
$type = $smarty->default_resource_type;
$name = $template_resource;
}
// create new source object
$source = new Source($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
$source->_getDefaultTemplate($_template->smarty->default_template_handler_func);
$source->handler->populate($source, $_template);
}
return $source;
}
/**
* Get source time stamp
*
* @return int
*/
public function getTimeStamp() {
if (!isset($this->timestamp)) {
$this->handler->populateTimestamp($this);
}
return $this->timestamp;
}
/**
* Get source content
*
* @return string
* @throws \SmartyException
*/
public function getContent() {
return isset($this->content) ? $this->content : $this->handler->getContent($this);
}
/**
* get default content from template or config resource handler
*
* @throws \SmartyException
*/
public function _getDefaultTemplate($default_handler) {
$_content = $_timestamp = null;
$_return = call_user_func_array(
$default_handler,
[$this->type, $this->name, &$_content, &$_timestamp, $this->smarty]
);
if (is_string($_return)) {
$this->exists = is_file($_return);
if ($this->exists) {
$this->timestamp = filemtime($_return);
} else {
throw new SmartyException(
'Default handler: Unable to load ' .
($this->isConfig ? 'config' : 'template') .
" default file '{$_return}' for '{$this->type}:{$this->name}'"
);
}
$this->name = $this->filepath = $_return;
$this->uid = sha1($this->filepath);
} elseif ($_return === true) {
$this->content = $_content;
$this->exists = true;
$this->uid = $this->name = sha1($_content);
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
} else {
$this->exists = false;
throw new SmartyException(
'Default handler: No ' . ($this->isConfig ? 'config' : 'template') .
" default content for '{$this->type}:{$this->name}'"
);
}
}
}

View File

@@ -1,387 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Uwe Tews
* Date: 04.12.2014
* Time: 06:08
*/
/**
* Smarty Resource Data Object
* Cache Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Smarty_Template_Cached extends Smarty_Template_Resource_Base
{
/**
* Cache Is Valid
*
* @var boolean
*/
public $valid = null;
/**
* CacheResource Handler
*
* @var \Smarty\Cacheresource\Base
*/
public $handler = null;
/**
* Template Cache Id (Smarty_Internal_Template::$cache_id)
*
* @var string
*/
public $cache_id = null;
/**
* saved cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 0;
/**
* Id for cache locking
*
* @var string
*/
public $lock_id = null;
/**
* flag that cache is locked by this instance
*
* @var bool
*/
public $is_locked = false;
/**
* Source Object
*
* @var Smarty_Template_Source
*/
public $source = null;
/**
* Nocache hash codes of processed compiled templates
*
* @var array
*/
public $hashes = array();
/**
* Flag if this is a cache resource
*
* @var bool
*/
public $isCache = true;
/**
* create Cached Object container
*
* @param Smarty_Internal_Template $_template template object
*
* @throws \SmartyException
*/
public function __construct(Smarty_Internal_Template $_template)
{
$this->compile_id = $_template->compile_id;
$this->cache_id = $_template->cache_id;
$this->source = $_template->source;
$this->handler = \Smarty\Cacheresource\Base::load($_template->smarty);
}
/**
* @param Smarty_Internal_Template $_template
*
* @return Smarty_Template_Cached
*/
public static function load(Smarty_Internal_Template $_template)
{
$_template->cached = new Smarty_Template_Cached($_template);
$_template->cached->handler->populate($_template->cached, $_template);
// caching enabled ?
if (!$_template->caching || $_template->source->handler->recompiled
) {
$_template->cached->valid = false;
}
return $_template->cached;
}
/**
* Render cache template
*
* @param \Smarty_Internal_Template $_template
* @param bool $no_output_filter
*
* @throws \Exception
*/
public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
{
if ($this->isCached($_template)) {
if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new \Smarty\Debug();
}
$_template->smarty->_debug->start_cache($_template);
}
if (!$this->processed) {
$this->process($_template);
}
$this->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
return;
} else {
$this->updateCache($_template, $no_output_filter);
}
}
/**
* Check if cache is valid, lock cache if required
*
* @param \Smarty_Internal_Template $_template
*
* @return bool flag true if cache is valid
*/
public function isCached(Smarty_Internal_Template $_template)
{
if ($this->valid !== null) {
return $this->valid;
}
while (true) {
while (true) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$this->valid = false;
} else {
$this->valid = true;
}
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT
&& $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
) {
// lifetime expired
$this->valid = false;
}
if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON
&& $_template->source->getTimeStamp() > $this->timestamp
) {
$this->valid = false;
}
if ($this->valid || !$_template->smarty->cache_locking) {
break;
}
if (!$this->handler->locked($_template->smarty, $this)) {
$this->handler->acquireLock($_template->smarty, $this);
break 2;
}
$this->handler->populate($this, $_template);
}
if ($this->valid) {
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_cache($_template);
}
if ($this->handler->process($_template, $this) === false) {
$this->valid = false;
} else {
$this->processed = true;
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
} else {
$this->is_locked = true;
continue;
}
} else {
return $this->valid;
}
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED
&& $_template->cached->cache_lifetime >= 0
&& (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
) {
$this->valid = false;
}
if ($_template->smarty->cache_locking) {
if (!$this->valid) {
$this->handler->acquireLock($_template->smarty, $this);
} elseif ($this->is_locked) {
$this->handler->releaseLock($_template->smarty, $this);
}
}
return $this->valid;
}
return $this->valid;
}
/**
* Process cached template
*
* @param Smarty_Internal_Template $_template template object
* @param bool $update flag if called because cache update
*/
public function process(Smarty_Internal_Template $_template, $update = false)
{
if ($this->handler->process($_template, $this, $update) === false) {
$this->valid = false;
}
if ($this->valid) {
$this->processed = true;
} else {
$this->processed = false;
}
}
/**
* Read cache content from handler
*
* @param Smarty_Internal_Template $_template template object
*
* @return string|false content
*/
public function readCache(Smarty_Internal_Template $_template)
{
if (!$_template->source->handler->recompiled) {
return $this->handler->retrieveCachedContent($_template);
}
return false;
}
/**
* Write this cache object to handler
*
* @param string $content content to cache
*
* @return bool success
*/
public function writeCache(Smarty_Internal_Template $_template, $content)
{
if (!$_template->source->handler->recompiled) {
if ($this->handler->storeCachedContent($_template, $content)) {
$this->content = null;
$this->timestamp = time();
$this->exists = true;
$this->valid = true;
$this->cache_lifetime = $_template->cache_lifetime;
$this->processed = false;
if ($_template->smarty->cache_locking) {
$this->handler->releaseLock($_template->smarty, $this);
}
return true;
}
$this->content = null;
$this->timestamp = false;
$this->exists = false;
$this->valid = false;
$this->processed = false;
}
return false;
}
/**
* Cache was invalid , so render from compiled and write to cache
*
* @param \Smarty_Template_Cached $cached
* @param $no_output_filter
*
* @throws \Exception
*/
public function updateCache(Smarty_Internal_Template $_template, $no_output_filter)
{
ob_start();
if (!isset($_template->compiled)) {
$_template->loadCompiled();
}
$_template->compiled->render($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_cache($_template);
}
$this->removeNoCacheHash($_template, $no_output_filter);
$compile_check = (int)$_template->compile_check;
$_template->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
if ($_template->_isSubTpl()) {
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
}
if (!$_template->cached->processed) {
$_template->cached->process($_template, true);
}
$_template->compile_check = $compile_check;
$this->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
}
/**
* Sanitize content and write it to cache resource
*
* @param Smarty_Internal_Template $_template
* @param bool $no_output_filter
*
* @throws \SmartyException
*/
private function removeNoCacheHash(Smarty_Internal_Template $_template, $no_output_filter) {
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
$content = ob_get_clean();
$hash_array = $this->hashes;
$hash_array[ $_template->compiled->nocache_hash ] = true;
$hash_array = array_keys($hash_array);
$nocache_hash = '(' . implode('|', $hash_array) . ')';
$_template->cached->has_nocache_code = false;
// get text between non-cached items
$cache_split =
preg_split(
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content
);
// get non-cached items
preg_match_all(
"!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content,
$cache_parts
);
$content = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
if (preg_match($php_pattern, $curr_split)) {
// escape PHP tags in template content
$php_split = preg_split(
$php_pattern,
$curr_split
);
preg_match_all(
$php_pattern,
$curr_split,
$php_parts
);
foreach ($php_split as $idx_php => $curr_php) {
$content .= $curr_php;
if (isset($php_parts[ 0 ][ $idx_php ])) {
$content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
}
}
} else {
$content .= $curr_split;
}
if (isset($cache_parts[ 0 ][ $curr_idx ])) {
$_template->cached->has_nocache_code = true;
$content .= $cache_parts[ 2 ][ $curr_idx ];
}
}
if (
!$no_output_filter
&& !$_template->cached->has_nocache_code
&& isset($_template->smarty->registered_filters[ 'output' ])
) {
$content = $_template->smarty->runFilter('output', $content, $_template);
}
// write cache file content
$_template->writeCachedContent($content);
}
}

View File

@@ -1,257 +0,0 @@
<?php
/**
* Smarty Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @property string $content compiled content
*/
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
{
/**
* nocache hash
*
* @var string|null
*/
public $nocache_hash = null;
/**
* get a Compiled Object of this source
*
* @param Smarty_Internal_Template $_template template object
*
* @return Smarty_Template_Compiled compiled object
*/
public static function load($_template)
{
$compiled = new Smarty_Template_Compiled();
if ($_template->source->handler->hasCompiledHandler) {
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else {
$compiled->populateCompiledFilepath($_template);
}
return $compiled;
}
/**
* populate Compiled Object with compiled filepath
*
* @param Smarty_Internal_Template $_template template object
**/
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
{
$source = &$_template->source;
$smarty = &$_template->smarty;
$this->filepath = $smarty->getCompileDir();
if (isset($_template->compile_id)) {
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DIRECTORY_SEPARATOR . $source->uid[ 2 ] .
$source->uid[ 3 ] . DIRECTORY_SEPARATOR . $source->uid[ 4 ] . $source->uid[ 5 ] .
DIRECTORY_SEPARATOR;
}
$this->filepath .= $source->uid . '_';
if ($source->isConfig) {
$this->filepath .= (int)$smarty->config_read_hidden + (int)$smarty->config_booleanize * 2 +
(int)$smarty->config_overwrite * 4;
} else {
$this->filepath .= (int)$smarty->merge_compiled_includes + (int)$smarty->escape_html * 2 +
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
(int)$smarty->extends_recursion * 4 : 0);
}
$this->filepath .= '.' . $source->type;
$basename = $source->handler->getBasename($source);
if (!empty($basename)) {
$this->filepath .= '.' . $basename;
}
if ($_template->caching) {
$this->filepath .= '.cache';
}
$this->filepath .= '.php';
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = filemtime($this->filepath);
}
}
/**
* render compiled template code
*
* @param Smarty_Internal_Template $_template
*
* @return string
* @throws Exception
*/
public function render(Smarty_Internal_Template $_template)
{
// checks if template exists
if (!$_template->source->exists) {
$type = $_template->source->isConfig ? 'config' : 'template';
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
}
if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new \Smarty\Debug();
}
$_template->smarty->_debug->start_render($_template);
}
if (!$this->processed) {
$this->process($_template);
}
if (isset($_template->cached)) {
$_template->cached->file_dependency =
array_merge($_template->cached->file_dependency, $this->file_dependency);
}
if ($_template->source->handler->uncompiled) {
$_template->source->handler->renderUncompiled($_template->source, $_template);
} else {
$this->getRenderedTemplateCode($_template);
}
if ($_template->caching && $this->has_nocache_code) {
$_template->cached->hashes[ $this->nocache_hash ] = true;
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_render($_template);
}
}
/**
* load compiled template or compile from source
*
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
*
* @throws Exception
*/
public function process(Smarty_Internal_Template $_smarty_tpl)
{
$source = &$_smarty_tpl->source;
$smarty = &$_smarty_tpl->smarty;
if ($source->handler->recompiled) {
$source->handler->process($_smarty_tpl);
} elseif (!$source->handler->uncompiled) {
if (!$this->exists || $smarty->force_compile
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
) {
$this->compileTemplateSource($_smarty_tpl);
$compileCheck = $_smarty_tpl->compile_check;
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
$this->loadCompiledTemplate($_smarty_tpl);
$_smarty_tpl->compile_check = $compileCheck;
} else {
$_smarty_tpl->mustCompile = true;
@include $this->filepath;
if ($_smarty_tpl->mustCompile) {
$this->compileTemplateSource($_smarty_tpl);
$compileCheck = $_smarty_tpl->compile_check;
$_smarty_tpl->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
$this->loadCompiledTemplate($_smarty_tpl);
$_smarty_tpl->compile_check = $compileCheck;
}
}
$_smarty_tpl->_subTemplateRegister();
$this->processed = true;
}
}
/**
* compile template from source
*
* @param Smarty_Internal_Template $_template
*
* @throws Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
$this->file_dependency = array();
$this->includes = array();
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
$saved_timestamp = $this->getTimeStamp();
touch($this->filepath);
}
// compile locking
try {
// call compiler
$_template->loadCompiler();
$this->write($_template, $_template->compiler->compileTemplate($_template));
} catch (Exception $e) {
// restore old timestamp in case of error
if ($saved_timestamp && is_file($this->filepath)) {
touch($this->filepath, $saved_timestamp);
}
unset($_template->compiler);
throw $e;
}
// release compiler object to free memory
unset($_template->compiler);
}
/**
* Write compiled code by handler
*
* @param Smarty_Internal_Template $_template template object
* @param string $code compiled code
*
* @return bool success
* @throws \SmartyException
*/
public function write(Smarty_Internal_Template $_template, $code)
{
if (!$_template->source->handler->recompiled) {
if ($_template->smarty->writeFile($this->filepath, $code) === true) {
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = filemtime($this->filepath);
return true;
}
}
return false;
}
return true;
}
/**
* Read compiled content from handler
*
* @param Smarty_Internal_Template $_template template object
*
* @return string content
*/
public function read(Smarty_Internal_Template $_template)
{
if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath);
}
return isset($this->content) ? $this->content : false;
}
/**
* Load fresh compiled template by including the PHP file
* HHVM requires a work around because of a PHP incompatibility
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
*/
private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
{
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
if (defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($this->filepath));
} else {
include $this->filepath;
}
}
}

View File

@@ -1,100 +0,0 @@
<?php
/**
* Smarty Config Source Plugin
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
*/
/**
* Smarty Config Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
*/
class Smarty_Template_Config extends Smarty_Template_Source
{
/**
* array of section names, single section or null
*
* @var null|string|array
*/
public $config_sections = null;
/**
* scope into which the config variables shall be loaded
*
* @var int
*/
public $scope = 0;
/**
* Flag that source is a config file
*
* @var bool
*/
public $isConfig = true;
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty\Compiler\ConfigFile';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Configfileparser';
/**
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Config Source Object
* @throws SmartyException
*/
public static function load(
Smarty_Internal_Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
static $_incompatible_resources = array('extends' => true, 'php' => true);
if ($_template) {
$smarty = $_template->smarty;
$template_resource = $_template->template_resource;
}
if (empty($template_resource)) {
throw new SmartyException('Source: Missing name');
}
// parse resource_name, load resource handler
list($name, $type) = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[ $type ])) {
throw new SmartyException("Unable to use resource '{$type}' for config");
}
$source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template);
if (!$source->exists && isset($smarty->default_config_handler_func)) {
$source->_getDefaultTemplate($smarty->default_config_handler_func);
$source->handler->populate($source, $_template);
}
return $source;
}
}

View File

@@ -1,152 +0,0 @@
<?php
/**
* Smarty Template Resource Base Object
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
abstract class Smarty_Template_Resource_Base
{
/**
* Compiled Filepath
*
* @var string
*/
public $filepath = null;
/**
* Compiled Timestamp
*
* @var integer|bool
*/
public $timestamp = false;
/**
* Compiled Existence
*
* @var boolean
*/
public $exists = false;
/**
* Template Compile Id (Smarty_Internal_Template::$compile_id)
*
* @var string
*/
public $compile_id = null;
/**
* Compiled Content Loaded
*
* @var boolean
*/
public $processed = false;
/**
* unique function name for compiled template code
*
* @var string
*/
public $unifunc = '';
/**
* flag if template does contain nocache code sections
*
* @var bool
*/
public $has_nocache_code = false;
/**
* resource file dependency
*
* @var array
*/
public $file_dependency = array();
/**
* Content buffer
*
* @var string
*/
public $content = null;
/**
* Included sub templates
* - index name
* - value use count
*
* @var int[]
*/
public $includes = array();
/**
* Flag if this is a cache resource
*
* @var bool
*/
public $isCache = false;
/**
* Process resource
*
* @param Smarty_Internal_Template $_template template object
*/
abstract public function process(Smarty_Internal_Template $_template);
/**
* get rendered template content by calling compiled or cached template code
*
* @param \Smarty_Internal_Template $_template
* @param string $unifunc function with template code
*
* @throws \Exception
*/
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
{
$smarty = &$_template->smarty;
$_template->isRenderingCache = $this->isCache;
$level = ob_get_level();
try {
if (!isset($unifunc)) {
$unifunc = $this->unifunc;
}
if (empty($unifunc) || !function_exists($unifunc)) {
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
}
if ($_template->startRenderCallbacks) {
foreach ($_template->startRenderCallbacks as $callback) {
call_user_func($callback, $_template);
}
}
$unifunc($_template);
foreach ($_template->endRenderCallbacks as $callback) {
call_user_func($callback, $_template);
}
$_template->isRenderingCache = false;
} catch (Exception $e) {
$_template->isRenderingCache = false;
while (ob_get_level() > $level) {
ob_end_clean();
}
if (isset($smarty->security_policy)) {
$smarty->security_policy->endTemplate();
}
throw $e;
}
}
/**
* Get compiled time stamp
*
* @return int
*/
public function getTimeStamp()
{
if ($this->exists && !$this->timestamp) {
$this->timestamp = filemtime($this->filepath);
}
return $this->timestamp;
}
}

View File

@@ -1,251 +0,0 @@
<?php
/**
* Smarty Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Smarty_Template_Source
{
/**
* Unique Template ID
*
* @var string
*/
public $uid = null;
/**
* Template Resource (Smarty_Internal_Template::$template_resource)
*
* @var string
*/
public $resource = null;
/**
* Resource Type
*
* @var string
*/
public $type = null;
/**
* Resource Name
*
* @var string
*/
public $name = null;
/**
* Source Filepath
*
* @var string
*/
public $filepath = null;
/**
* Source Timestamp
*
* @var integer
*/
public $timestamp = null;
/**
* Source Existence
*
* @var boolean
*/
public $exists = false;
/**
* Source File Base name
*
* @var string
*/
public $basename = null;
/**
* The Components an extended template is made of
*
* @var \Smarty_Template_Source[]
*/
public $components = null;
/**
* Resource Handler
*
* @var \Smarty\Resource\BasePlugin
*/
public $handler = null;
/**
* Smarty instance
*
* @var Smarty
*/
public $smarty = null;
/**
* Resource is source
*
* @var bool
*/
public $isConfig = false;
/**
* Template source content eventually set by default handler
*
* @var string
*/
public $content = null;
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty\Compiler\Template';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* create Source Object container
*
* @param Smarty $smarty Smarty instance this source object belongs to
* @param string $resource full template_resource
* @param string $type type of resource
* @param string $name resource name
*
* @throws \SmartyException
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
*/
public function __construct(Smarty $smarty, $resource, $type, $name)
{
$this->handler = Smarty\Resource\BasePlugin::load($smarty, $type);
$this->smarty = $smarty;
$this->resource = $resource;
$this->type = $type;
$this->name = $name;
}
/**
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Source Source Object
* @throws SmartyException
*/
public static function load(
Smarty_Internal_Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
if ($_template) {
$smarty = $_template->smarty;
$template_resource = $_template->template_resource;
}
if (empty($template_resource)) {
throw new SmartyException('Source: Missing name');
}
// parse resource_name, load resource handler, identify unique resource name
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
$type = $match[ 1 ];
$name = $match[ 2 ];
} else {
// no resource given, use default
// or single character before the colon is not a resource type, but part of the filepath
$type = $smarty->default_resource_type;
$name = $template_resource;
}
// create new source object
$source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
$source->_getDefaultTemplate($_template->smarty->default_template_handler_func);
$source->handler->populate($source, $_template);
}
return $source;
}
/**
* Get source time stamp
*
* @return int
*/
public function getTimeStamp()
{
if (!isset($this->timestamp)) {
$this->handler->populateTimestamp($this);
}
return $this->timestamp;
}
/**
* Get source content
*
* @return string
* @throws \SmartyException
*/
public function getContent()
{
return isset($this->content) ? $this->content : $this->handler->getContent($this);
}
/**
* get default content from template or config resource handler
*
* @throws \SmartyException
*/
public function _getDefaultTemplate($default_handler)
{
$_content = $_timestamp = null;
$_return = call_user_func_array(
$default_handler,
array($this->type, $this->name, &$_content, &$_timestamp, $this->smarty)
);
if (is_string($_return)) {
$this->exists = is_file($_return);
if ($this->exists) {
$this->timestamp = filemtime($_return);
} else {
throw new SmartyException(
'Default handler: Unable to load ' .
($this->isConfig ? 'config' : 'template') .
" default file '{$_return}' for '{$this->type}:{$this->name}'"
);
}
$this->name = $this->filepath = $_return;
$this->uid = sha1($this->filepath);
} elseif ($_return === true) {
$this->content = $_content;
$this->exists = true;
$this->uid = $this->name = sha1($_content);
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
} else {
$this->exists = false;
throw new SmartyException(
'Default handler: No ' . ($this->isConfig ? 'config' : 'template') .
" default content for '{$this->type}:{$this->name}'"
);
}
}
}

894
src/TemplateBase.php Normal file
View File

@@ -0,0 +1,894 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Base
* This file contains the basic shared methods for template handling
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
namespace Smarty;
use Smarty\Cacheresource\Base;
use Smarty\Data;
use Smarty\Smarty;
use Smarty\Template;
use Smarty_Data;
use SmartyException;
/**
* Class with shared smarty/template methods
*
* @property int $_objType
*
*/
abstract class TemplateBase extends Data {
/**
* Set this if you want different sets of cache files for the same
* templates.
*
* @var string
*/
public $cache_id = null;
/**
* Set this if you want different sets of compiled files for the same
* templates.
*
* @var string
*/
public $compile_id = null;
/**
* caching enabled
*
* @var int
*/
public $caching = \Smarty\Smarty::CACHING_OFF;
/**
* check template for modifications?
*
* @var int
*/
public $compile_check = \Smarty\Smarty::COMPILECHECK_ON;
/**
* cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 3600;
/**
* Array of source information for known template functions
*
* @var array
*/
public $tplFunctions = [];
/**
* When initialized to an (empty) array, this variable will hold a stack of template variables.
*
* @var null|array
*/
public $_var_stack = null;
/**
* Valid filter types
*
* @var array
*/
private $filterTypes = ['pre' => true, 'post' => true, 'output' => true, 'variable' => true];
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return string rendered template output
* @throws SmartyException
* @throws Exception
*/
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) {
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
return $result === null ? ob_get_clean() : $result;
}
/**
* displays a Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @throws \Exception
* @throws \SmartyException
*/
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {
// display template
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
}
/**
* test if cache is valid
*
* @param null|string|\Smarty\Template $template the resource handle of the template file or template
* object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return bool cache status
* @throws \Exception
* @throws \SmartyException
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
*
* @api Smarty::isCached()
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) {
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
}
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
*
* @return mixed
* @throws \Exception
* @throws \SmartyException
*/
private function _execute($template, $cache_id, $compile_id, $parent, $function) {
$smarty = $this->_getSmartyObj();
$saveVars = true;
if ($template === null) {
if (!$this->_isTplObj()) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = $this;
}
} elseif (is_object($template)) {
/* @var Template $template */
if (!isset($template->_objType) || !$template->_isTplObj()) {
throw new SmartyException($function . '():Template object expected');
}
} else {
// get template object
$saveVars = false;
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
if ($this->_objType === 1) {
// set caching in template object
$template->caching = $this->caching;
}
}
// make sure we have integer values
$template->caching = (int)$template->caching;
// fetch template content
$level = ob_get_level();
try {
$_smarty_old_error_level =
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
if ($smarty->isMutingUndefinedOrNullWarnings()) {
$errorHandler = new \Smarty\ErrorHandler();
$errorHandler->activate();
}
if ($this->_objType === 2) {
/* @var Template $this */
$template->tplFunctions = $this->tplFunctions;
$template->inheritance = $this->inheritance;
}
/* @var Template $parent */
if (isset($parent->_objType) && ($parent->_objType === 2) && !empty($parent->tplFunctions)) {
$template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
}
if ($function === 2) {
if ($template->caching) {
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
$result = $template->cached->isCached($template);
Template::$isCacheTplObj[$template->_getTemplateId()] = $template;
} else {
return false;
}
} else {
if ($saveVars) {
$savedTplVars = $template->tpl_vars;
$savedConfigVars = $template->config_vars;
}
ob_start();
$template->_mergeVars();
if (!empty(\Smarty\Smarty::$global_tpl_vars)) {
$template->tpl_vars = array_merge(\Smarty\Smarty::$global_tpl_vars, $template->tpl_vars);
}
$result = $template->render(false, $function);
$template->_cleanUp();
if ($saveVars) {
$template->tpl_vars = $savedTplVars;
$template->config_vars = $savedConfigVars;
} else {
if (!$function && !isset(Template::$tplObjCache[$template->templateId])) {
$template->parent = null;
$template->tpl_vars = $template->config_vars = [];
Template::$tplObjCache[$template->templateId] = $template;
}
}
}
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
return $result;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
throw $e;
}
}
/**
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $name name of template tag
* @param callable $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
*
* @return \Smarty|\Smarty\Template
* @throws \SmartyException
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl
*
* @api Smarty::registerPlugin()
*/
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) {
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_plugins[$type][$name])) {
throw new SmartyException("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin '{$name}' not callable");
} elseif ($cacheable && $cache_attr) {
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
} else {
$smarty->registered_plugins[$type][$name] = [$callback, (bool)$cacheable, (array)$cache_attr];
}
return $this;
}
/**
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $name name of template tag
*
* @return \Smarty|\Smarty\Template
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
*
* @api Smarty::unregisterPlugin()
*/
public function unregisterPlugin($type, $name) {
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_plugins[$type][$name])) {
unset($smarty->registered_plugins[$type][$name]);
}
return $this;
}
/**
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws \SmartyException
* @api Smarty::loadFilter()
* @link https://www.smarty.net/docs/en/api.load.filter.tpl
*
*/
public function loadFilter($type, $name) {
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
if (class_exists($_plugin, false)) {
$_plugin = [$_plugin, 'execute'];
}
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
throw new SmartyException("{$type}filter '{$name}' not found or callable");
}
/**
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
*
* @return TemplateBase
* @throws \SmartyException
* @api Smarty::unloadFilter()
*
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl
*
*/
public function unloadFilter($type, $name) {
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[$type])) {
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($smarty->registered_filters[$type][$_filter_name])) {
unset($smarty->registered_filters[$type][$_filter_name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
return $this;
}
/**
* Registers a filter function
*
* @param string $type filter type
* @param callable $callback
* @param string|null $name optional filter name
*
* @return TemplateBase
* @throws \SmartyException
* @link https://www.smarty.net/docs/en/api.register.filter.tpl
*
* @api Smarty::registerFilter()
*/
public function registerFilter($type, $callback, $name = null) {
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) {
throw new SmartyException("{$type}filter '{$name}' not callable");
}
$smarty->registered_filters[$type][$name] = $callback;
return $this;
}
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback|string $callback
*
* @return TemplateBase
* @throws \SmartyException
* @api Smarty::unregisterFilter()
*
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
*
*/
public function unregisterFilter($type, $callback) {
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[$type])) {
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
if (isset($smarty->registered_filters[$type][$name])) {
unset($smarty->registered_filters[$type][$name]);
if (empty($smarty->registered_filters[$type])) {
unset($smarty->registered_filters[$type]);
}
}
}
return $this;
}
/**
* Registers object to be used in templates
*
* @param string $object_name
* @param object $object the referenced PHP object to register
* @param array $allowed_methods_properties list of allowed methods (empty = all)
* @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty|\Smarty\Template
* @throws \SmartyException
* @link https://www.smarty.net/docs/en/api.register.object.tpl
*
* @api Smarty::registerObject()
*/
public function registerObject(
$object_name,
$object,
$allowed_methods_properties = [],
$format = true,
$block_methods = []
) {
$smarty = $this->_getSmartyObj();
// test if allowed methods callable
if (!empty($allowed_methods_properties)) {
foreach ((array)$allowed_methods_properties as $method) {
if (!is_callable([$object, $method]) && !property_exists($object, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array)$block_methods as $method) {
if (!is_callable([$object, $method])) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty->registered_objects[$object_name] =
[$object, (array)$allowed_methods_properties, (boolean)$format, (array)$block_methods];
return $this;
}
/**
* Registers plugin to be used in templates
*
* @param string $object_name name of object
*
* @return TemplateBase
* @api Smarty::unregisterObject()
* @link https://www.smarty.net/docs/en/api.unregister.object.tpl
*
*/
public function unregisterObject($object_name) {
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_objects[$object_name])) {
unset($smarty->registered_objects[$object_name]);
}
return $this;
}
/**
* @param int $compile_check
*/
public function setCompileCheck($compile_check) {
$this->compile_check = (int)$compile_check;
}
/**
* @param int $caching
*/
public function setCaching($caching) {
$this->caching = (int)$caching;
}
/**
* @param int $cache_lifetime
*/
public function setCacheLifetime($cache_lifetime) {
$this->cache_lifetime = $cache_lifetime;
}
/**
* @param string $compile_id
*/
public function setCompileId($compile_id) {
$this->compile_id = $compile_id;
}
/**
* @param string $cache_id
*/
public function setCacheId($cache_id) {
$this->cache_id = $cache_id;
}
/**
* Add default modifiers
*
* @param array|string $modifiers modifier or list of modifiers
* to add
*
* @return \Smarty|\Smarty\Template
* @api Smarty::addDefaultModifiers()
*
*/
public function addDefaultModifiers($modifiers) {
$smarty = $this->_getSmartyObj();
if (is_array($modifiers)) {
$smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {
$smarty->default_modifiers[] = $modifiers;
}
return $this;
}
/**
* creates a data object
*
* @param Data|null $parent next higher level of Smarty
* variables
* @param null $name optional data block name
*
* @return Smarty_Data data object
* @throws SmartyException
* @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
*
*/
public function createData(Data $parent = null, $name = null) {
/* @var Smarty $smarty */
$smarty = $this->_getSmartyObj();
$dataObj = new Smarty_Data($parent, $smarty, $name);
if ($smarty->debugging) {
\Smarty\Debug::register_data($dataObj);
}
return $dataObj;
}
/**
* return name of debugging template
*
* @return string
* @api Smarty::getDebugTemplate()
*
*/
public function getDebugTemplate() {
$smarty = $this->_getSmartyObj();
return $smarty->debug_tpl;
}
/**
* Get default modifiers
*
* @return array list of default modifiers
* @api Smarty::getDefaultModifiers()
*
*/
public function getDefaultModifiers() {
$smarty = $this->_getSmartyObj();
return $smarty->default_modifiers;
}
/**
* return a reference to a registered object
*
* @param string $object_name object name
*
* @return object
* @throws \SmartyException if no such object is found
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
*
* @api Smarty::getRegisteredObject()
*/
public function getRegisteredObject($object_name) {
$smarty = $this->_getSmartyObj();
if (!isset($smarty->registered_objects[$object_name])) {
throw new SmartyException("'$object_name' is not a registered object");
}
if (!is_object($smarty->registered_objects[$object_name][0])) {
throw new SmartyException("registered '$object_name' is not an object");
}
return $smarty->registered_objects[$object_name][0];
}
/**
* Get literals
*
* @return array list of literals
* @api Smarty::getLiterals()
*
*/
public function getLiterals() {
$smarty = $this->_getSmartyObj();
return (array)$smarty->literals;
}
/**
* Add literals
*
* @param array|string $literals literal or list of literals
* to addto add
*
* @return TemplateBase
* @throws \SmartyException
* @api Smarty::addLiterals()
*
*/
public function addLiterals($literals = null) {
if (isset($literals)) {
$this->_setLiterals($this->_getSmartyObj(), (array)$literals);
}
return $this;
}
/**
* Set literals
*
* @param array|string $literals literal or list of literals
* to setto set
*
* @return TemplateBase
* @throws \SmartyException
* @api Smarty::setLiterals()
*
*/
public function setLiterals($literals = null) {
$smarty = $this->_getSmartyObj();
$smarty->literals = [];
if (!empty($literals)) {
$this->_setLiterals($smarty, (array)$literals);
}
return $this;
}
/**
* common setter for literals for easier handling of duplicates the
* Smarty::$literals array gets filled with identical key values
*
* @param Smarty $smarty
* @param array $literals
*
* @throws \SmartyException
*/
private function _setLiterals(Smarty $smarty, $literals) {
$literals = array_combine($literals, $literals);
$error = isset($literals[$smarty->left_delimiter]) ? [$smarty->left_delimiter] : [];
$error = isset($literals[$smarty->right_delimiter]) ? $error[] = $smarty->right_delimiter : $error;
if (!empty($error)) {
throw new SmartyException(
'User defined literal(s) "' . $error .
'" may not be identical with left or right delimiter'
);
}
$smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
private function _checkFilterType($type) {
if (!isset($this->filterTypes[$type])) {
throw new SmartyException("Illegal filter type '{$type}'");
}
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
private function _getFilterName($function_name) {
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} elseif (is_string($function_name)) {
return $function_name;
} else {
return 'closure';
}
}
/**
* Registers static classes to be used in templates
*
* @param string $class_name
* @param string $class_impl the referenced PHP class to
* register
*
* @return TemplateBase
* @throws \SmartyException
* @api Smarty::registerClass()
* @link https://www.smarty.net/docs/en/api.register.class.tpl
*
*/
public function registerClass($class_name, $class_impl) {
$smarty = $this->_getSmartyObj();
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");
}
// register the class
$smarty->registered_classes[$class_name] = $class_impl;
return $this;
}
/**
* Registers a resource to fetch a template
*
* @param string $name name of resource type
* @param Base $resource_handler
*
* @return TemplateBase
* @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
*
* @api Smarty::registerCacheResource()
*/
public function registerCacheResource($name, Base $resource_handler) {
$smarty = $this->_getSmartyObj();
$smarty->registered_cache_resources[$name] = $resource_handler;
return $this;
}
/**
* Unregisters a resource to fetch a template
*
* @param $name
*
* @return \Smarty|\Smarty\Template
* @api Smarty::unregisterCacheResource()
* @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
*
*/
public function unregisterCacheResource($name) {
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_cache_resources[$name])) {
unset($smarty->registered_cache_resources[$name]);
}
return $this;
}
/**
* Register config default handler
*
* @param callable $callback class/method name
*
* @return TemplateBase
* @throws SmartyException if $callback is not callable
* @api Smarty::registerDefaultConfigHandler()
*
*/
public function registerDefaultConfigHandler($callback) {
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException('Default config handler not callable');
}
return $this;
}
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
*
* @return TemplateBase
* @throws SmartyException if $callback is not callable
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
*
* @api Smarty::registerDefaultPluginHandler()
*/
public function registerDefaultPluginHandler($callback) {
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $this;
}
/**
* Register template default handler
*
* @param callable $callback class/method name
*
* @return TemplateBase
* @throws SmartyException if $callback is not callable
* @api Smarty::registerDefaultTemplateHandler()
*
*/
public function registerDefaultTemplateHandler($callback) {
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException('Default template handler not callable');
}
return $this;
}
/**
* Registers a resource to fetch a template
*
* @param string $name name of resource type
* @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base
*
* @return \Smarty|\Smarty\Template
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
*
* @api Smarty::registerResource()
*/
public function registerResource($name, Smarty\Resource\Base $resource_handler) {
$smarty = $this->_getSmartyObj();
$smarty->registered_resources[$name] = $resource_handler;
return $this;
}
/**
* Unregisters a resource to fetch a template
*
* @param string $type name of resource type
*
* @return TemplateBase
* @api Smarty::unregisterResource()
* @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
*
*/
public function unregisterResource($type) {
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_resources[$type])) {
unset($smarty->registered_resources[$type]);
}
return $this;
}
/**
* set the debug template
*
* @param string $tpl_name
*
* @return TemplateBase
* @throws SmartyException if file is not readable
* @api Smarty::setDebugTemplate()
*
*/
public function setDebugTemplate($tpl_name) {
$smarty = $this->_getSmartyObj();
if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'");
}
$smarty->debug_tpl = $tpl_name;
return $this;
}
/**
* Set default modifiers
*
* @param array|string $modifiers modifier or list of modifiers
* to set
*
* @return TemplateBase
* @api Smarty::setDefaultModifiers()
*
*/
public function setDefaultModifiers($modifiers) {
$smarty = $this->_getSmartyObj();
$smarty->default_modifiers = (array)$modifiers;
return $this;
}
}

View File

@@ -1,16 +0,0 @@
<?php
/**
* This file is part of the Smarty package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Load and register Smarty Autoloader
*/
if (!class_exists('Smarty_Autoloader')) {
include __DIR__ . '/Autoloader.php';
}
Smarty_Autoloader::register(true);

View File

@@ -1,930 +0,0 @@
<?php
/**
* Smarty Internal Plugin Template
* This file contains the Smarty template engine
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
use Smarty\Data;
use Smarty\Runtime\InheritanceRuntime;
/**
* Main class with template data structures and methods
*
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
* @property \Smarty\Compiler\Template $compiler
* @property mixed|\Smarty_Template_Cached registered_plugins
*/
#[\AllowDynamicProperties]
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{
/**
* Template object cache
*
* @var Smarty_Internal_Template[]
*/
public static $tplObjCache = array();
/**
* Template object cache for Smarty::isCached() === true
*
* @var Smarty_Internal_Template[]
*/
public static $isCacheTplObj = array();
/**
* Sub template Info Cache
* - index name
* - value use count
*
* @var int[]
*/
public static $subTplInfo = array();
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 2;
/**
* Source instance
*
* @var Smarty_Template_Source|Smarty_Template_Config
*/
public $source = null;
/**
* Inheritance runtime extension
*
* @var InheritanceRuntime
*/
public $inheritance = null;
/**
* Template resource
*
* @var string
*/
public $template_resource = null;
/**
* flag if compiled template is invalid and must be (re)compiled
*
* @var bool
*/
public $mustCompile = null;
/**
* Template Id
*
* @var null|string
*/
public $templateId = null;
/**
* Scope in which variables shall be assigned
*
* @var int
*/
public $scope = 0;
/**
* Flag which is set while rending a cache file
*
* @var bool
*/
public $isRenderingCache = false;
/**
* Callbacks called before rendering template
*
* @var callback[]
*/
public $startRenderCallbacks = array();
/**
* Callbacks called after rendering template
*
* @var callback[]
*/
public $endRenderCallbacks = array();
/**
* @var \Smarty\Compiler\CodeFrame
*/
private $codeFrameCompiler;
/**
* Create template data object
* Some of the global Smarty settings copied to template scope
* It load the required template resources and caching plugins
*
* @param string $template_resource template resource string
* @param Smarty $smarty Smarty instance
* @param null|\Smarty_Internal_Template|\Smarty|\Smarty\Data $_parent back pointer to parent
* object with variables or
* null
* @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null
* @param bool|int|null $_caching use caching?
* @param int|null $_cache_lifetime cache life-time in
* seconds
* @param bool $_isConfig
*
* @throws \SmartyException
*/
public function __construct(
$template_resource,
Smarty $smarty,
\Smarty\Data $_parent = null,
$_cache_id = null,
$_compile_id = null,
$_caching = null,
$_cache_lifetime = null,
$_isConfig = false
) {
$this->smarty = $smarty;
// Smarty parameter
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
$this->caching = (int)($_caching === null ? $this->smarty->caching : $_caching);
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
$this->compile_check = (int)$smarty->compile_check;
$this->parent = $_parent;
// Template resource
$this->template_resource = $template_resource;
$this->source = $_isConfig ? Smarty_Template_Config::load($this) : Smarty_Template_Source::load($this);
parent::__construct();
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
$smarty->security_policy->registerCallBacks($this);
}
$this->codeFrameCompiler = new Smarty\Compiler\CodeFrame($this);
}
/**
* render template
*
* @param bool $no_output_filter if true do not run output filter
* @param null|bool $display true: display, false: fetch null: sub-template
*
* @return string
* @throws \Exception
* @throws \SmartyException
*/
public function render($no_output_filter = true, $display = null)
{
if ($this->smarty->debugging) {
if (!isset($this->smarty->_debug)) {
$this->smarty->_debug = new \Smarty\Debug();
}
$this->smarty->_debug->start_template($this, $display);
}
// checks if template exists
if (!$this->source->exists) {
throw new SmartyException(
"Unable to load template '{$this->source->type}:{$this->source->name}'" .
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
);
}
// disable caching for evaluated code
if ($this->source->handler->recompiled) {
$this->caching = \Smarty\Smarty::CACHING_OFF;
}
// read from cache or render
if ($this->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT || $this->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED) {
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|| $this->cached->compile_id !== $this->compile_id
) {
$this->loadCached(true);
}
$this->cached->render($this, $no_output_filter);
} else {
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
$this->loadCompiled(true);
}
$this->compiled->render($this);
}
// display or fetch
if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) {
$this->smarty->cacheModifiedCheck(
$this->cached,
$this,
isset($content) ? $content : ob_get_clean()
);
} else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& !$no_output_filter && isset($this->smarty->registered_filters[ 'output' ])
) {
echo $this->smarty->runFilter('output', ob_get_clean(), $this);
} else {
echo ob_get_clean();
}
}
if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this);
// debug output
$this->smarty->_debug->display_debug($this, true);
}
return '';
} else {
if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this);
if ($this->smarty->debugging === 2 && $display === false) {
$this->smarty->_debug->display_debug($this, true);
}
}
if (
!$no_output_filter
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& isset($this->smarty->registered_filters[ 'output' ])
) {
return $this->smarty->runFilter('output', ob_get_clean(), $this);
}
// return cache content
return null;
}
}
/**
* Runtime function to render sub-template
*
* @param string $template template name
* @param mixed $cache_id cache id
* @param mixed $compile_id compile id
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $scope scope in which {include} should execute
* @param bool $forceTplCache cache template object
* @param string $uid file dependency uid
* @param string $content_func function name
*
* @throws \Exception
* @throws \SmartyException
*/
public function _subTemplateRender(
$template,
$cache_id,
$compile_id,
$caching,
$cache_lifetime,
$data,
$scope,
$forceTplCache,
$uid = null,
$content_func = null
) {
$tpl = clone $this;
$tpl->parent = $this;
$smarty = &$this->smarty;
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
// recursive call ?
if ((isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId()) !== $_templateId) {
// already in template cache?
if (isset(self::$tplObjCache[ $_templateId ])) {
// copy data from cached object
$cachedTpl = &self::$tplObjCache[ $_templateId ];
$tpl->templateId = $cachedTpl->templateId;
$tpl->template_resource = $cachedTpl->template_resource;
$tpl->cache_id = $cachedTpl->cache_id;
$tpl->compile_id = $cachedTpl->compile_id;
$tpl->source = $cachedTpl->source;
if (isset($cachedTpl->compiled)) {
$tpl->compiled = $cachedTpl->compiled;
} else {
unset($tpl->compiled);
}
if ($caching !== 9999 && isset($cachedTpl->cached)) {
$tpl->cached = $cachedTpl->cached;
} else {
unset($tpl->cached);
}
} else {
$tpl->templateId = $_templateId;
$tpl->template_resource = $template;
$tpl->cache_id = $cache_id;
$tpl->compile_id = $compile_id;
if (isset($uid)) {
// for inline templates we can get all resource information from file dependency
[$filepath, $timestamp, $type] = $tpl->compiled->file_dependency[ $uid ];
$tpl->source = new Smarty_Template_Source($smarty, $filepath, $type, $filepath);
$tpl->source->filepath = $filepath;
$tpl->source->timestamp = $timestamp;
$tpl->source->exists = true;
$tpl->source->uid = $uid;
} else {
$tpl->source = Smarty_Template_Source::load($tpl);
unset($tpl->compiled);
}
if ($caching !== 9999) {
unset($tpl->cached);
}
}
} else {
// on recursive calls force caching
$forceTplCache = true;
}
$tpl->caching = $caching;
$tpl->cache_lifetime = $cache_lifetime;
// set template scope
$tpl->scope = $scope;
if (!isset(self::$tplObjCache[ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
// check if template object should be cached
if ($forceTplCache || (isset(self::$subTplInfo[ $tpl->template_resource ])
&& self::$subTplInfo[ $tpl->template_resource ] > 1)
|| ($tpl->_isSubTpl() && isset(self::$tplObjCache[ $tpl->parent->templateId ]))
) {
self::$tplObjCache[ $tpl->templateId ] = $tpl;
}
}
if (!empty($data)) {
// set up variable values
foreach ($data as $_key => $_val) {
$tpl->tpl_vars[ $_key ] = new \Smarty\Variable($_val, $this->isRenderingCache);
}
}
if ($tpl->caching === 9999) {
if (!isset($tpl->compiled)) {
$tpl->loadCompiled(true);
}
if ($tpl->compiled->has_nocache_code) {
$this->cached->hashes[ $tpl->compiled->nocache_hash ] = true;
}
}
$tpl->_cache = array();
if (isset($uid)) {
if ($smarty->debugging) {
if (!isset($smarty->_debug)) {
$smarty->_debug = new \Smarty\Debug();
}
$smarty->_debug->start_template($tpl);
$smarty->_debug->start_render($tpl);
}
$tpl->compiled->getRenderedTemplateCode($tpl, $content_func);
if ($smarty->debugging) {
$smarty->_debug->end_template($tpl);
$smarty->_debug->end_render($tpl);
}
} else {
if (isset($tpl->compiled)) {
$tpl->compiled->render($tpl);
} else {
$tpl->render();
}
}
}
/**
* Get called sub-templates and save call count
*/
public function _subTemplateRegister()
{
foreach ($this->compiled->includes as $name => $count) {
if (isset(self::$subTplInfo[ $name ])) {
self::$subTplInfo[ $name ] += $count;
} else {
self::$subTplInfo[ $name ] = $count;
}
}
}
/**
* Check if this is a sub template
*
* @return bool true is sub template
*/
public function _isSubTpl()
{
return isset($this->parent) && $this->parent->_isTplObj();
}
/**
* Assign variable in scope
*
* @param string $varName variable name
* @param mixed $value value
* @param bool $nocache nocache flag
* @param int $scope scope into which variable shall be assigned
*/
public function _assignInScope($varName, $value, $nocache = false, $scope = 0)
{
if (isset($this->tpl_vars[ $varName ])) {
$this->tpl_vars[ $varName ] = clone $this->tpl_vars[ $varName ];
$this->tpl_vars[ $varName ]->value = $value;
if ($nocache || $this->isRenderingCache) {
$this->tpl_vars[ $varName ]->nocache = true;
}
} else {
$this->tpl_vars[ $varName ] = new \Smarty\Variable($value, $nocache || $this->isRenderingCache);
}
if ($scope >= 0) {
if ($scope > 0 || $this->scope > 0) {
$this->_updateScope($varName, $scope);
}
}
}
/**
* This function is executed automatically when a compiled or cached template file is included
* - Decode saved properties from compiled template and cache files
* - Check if compiled or cache file is valid
*
* @param \Smarty_Internal_Template $tpl
* @param array $properties special template properties
* @param bool $cache flag if called from cache file
*
* @return bool flag if compiled or cache file is valid
* @throws \SmartyException
*/
public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
{
// on cache resources other than file check version stored in cache code
if (!isset($properties[ 'version' ]) || \Smarty\Smarty::SMARTY_VERSION !== $properties[ 'version' ]) {
if ($cache) {
$tpl->smarty->clearAllCache();
} else {
$tpl->smarty->clearCompiledTemplate();
}
return false;
}
$is_valid = true;
if (!empty($properties[ 'file_dependency' ])
&& ((!$cache && $tpl->compile_check) || $tpl->compile_check === \Smarty\Smarty::COMPILECHECK_ON)
) {
// check file dependencies at compiled code
foreach ($properties[ 'file_dependency' ] as $_file_to_check) {
if ($_file_to_check[ 2 ] === 'file' || $_file_to_check[ 2 ] === 'php') {
if ($tpl->source->filepath === $_file_to_check[ 0 ]) {
// do not recheck current template
continue;
//$mtime = $tpl->source->getTimeStamp();
} else {
// file and php types can be checked without loading the respective resource handlers
$mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false;
}
} else {
$handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[ 2 ]);
if ($handler->checkTimestamps()) {
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
$mtime = $source->getTimeStamp();
} else {
continue;
}
}
if ($mtime === false || $mtime > $_file_to_check[ 1 ]) {
$is_valid = false;
break;
}
}
}
if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($tpl->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED && $properties[ 'cache_lifetime' ] >= 0
&& (time() > ($tpl->cached->timestamp + $properties[ 'cache_lifetime' ]))
) {
$is_valid = false;
}
$tpl->cached->cache_lifetime = $properties[ 'cache_lifetime' ];
$tpl->cached->valid = $is_valid;
$resource = $tpl->cached;
} else {
$tpl->mustCompile = !$is_valid;
$resource = $tpl->compiled;
$resource->includes = isset($properties[ 'includes' ]) ? $properties[ 'includes' ] : array();
}
if ($is_valid) {
$resource->unifunc = $properties[ 'unifunc' ];
$resource->has_nocache_code = $properties[ 'has_nocache_code' ];
$resource->file_dependency = $properties[ 'file_dependency' ];
}
return $is_valid && !function_exists($properties[ 'unifunc' ]);
}
/**
* Compiles the template
* If the template is not evaluated the compiled template is saved on disk
*
* @throws \Exception
*/
public function compileTemplateSource()
{
return $this->compiled->compileTemplateSource($this);
}
/**
* Writes the content to cache resource
*
* @param string $content
*
* @return bool
*/
public function writeCachedContent($content)
{
if ($this->source->handler->recompiled || !$this->caching
) {
// don't write cache file
return false;
}
if (!isset($this->cached)) {
$this->loadCached();
}
$codeframe = $this->createCodeFrame($content, '', true);
return $this->cached->writeCache($this, $codeframe);
}
/**
* Get unique template id
*
* @return string
* @throws \SmartyException
*/
public function _getTemplateId()
{
return $this->templateId ?? $this->templateId =
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
}
/**
* runtime error not matching capture tags
*
* @throws \SmartyException
*/
public function capture_error()
{
throw new SmartyException("Not matching {capture} open/close in '{$this->template_resource}'");
}
/**
* Load compiled object
*
* @param bool $force force new compiled object
*/
public function loadCompiled($force = false)
{
if ($force || !isset($this->compiled)) {
$this->compiled = Smarty_Template_Compiled::load($this);
}
}
/**
* Load cached object
*
* @param bool $force force new cached object
*/
public function loadCached($force = false)
{
if ($force || !isset($this->cached)) {
$this->cached = Smarty_Template_Cached::load($this);
}
}
/**
* Load inheritance object
*/
public function _loadInheritance()
{
if (!isset($this->inheritance)) {
$this->inheritance = new InheritanceRuntime();
}
}
/**
* Unload inheritance object
*/
public function _cleanUp()
{
$this->startRenderCallbacks = array();
$this->endRenderCallbacks = array();
$this->inheritance = null;
}
/**
* Load compiler object
*
* @throws \SmartyException
*/
public function loadCompiler()
{
$this->compiler =
new $this->source->compiler_class(
$this->source->template_lexer_class,
$this->source->template_parser_class,
$this->smarty
);
}
/**
* Create code frame for compiled and cached templates
*
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty\Compiler\Template $compiler
*
* @return string
*/
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) {
return $this->codeFrameCompiler->create($content, $functions, $cache, $compiler);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @return mixed
*/
public function __call($name, $args)
{
// method of Smarty object?
if (method_exists($this->smarty, $name)) {
return call_user_func_array(array($this->smarty, $name), $args);
}
// parent
return parent::__call($name, $args);
}
/**
* get Smarty property in template context
*
* @param string $property_name property name
*
* @return mixed|Smarty_Template_Cached
* @throws SmartyException
*/
public function __get($property_name)
{
switch ($property_name) {
case 'compiled':
$this->loadCompiled();
return $this->compiled;
case 'cached':
$this->loadCached();
return $this->cached;
case 'compiler':
$this->loadCompiler();
return $this->compiler;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
return $this->smarty->$property_name;
}
}
throw new SmartyException("template property '$property_name' does not exist.");
}
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws SmartyException
*/
public function __set($property_name, $value)
{
switch ($property_name) {
case 'compiled':
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new SmartyException("invalid template property '$property_name'.");
}
/**
* Template data object destructor
*/
public function __destruct()
{
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
$this->cached->handler->releaseLock($this->smarty, $this->cached);
}
}
/**
* load config variables into template object
*
* @param \Smarty_Internal_Template $tpl
* @param array $new_config_vars
*/
public function _loadConfigVars($new_config_vars)
{
$this->_assignConfigVars($this->parent->config_vars, $new_config_vars);
$tagScope = $this->source->scope;
if ($tagScope >= 0) {
if ($tagScope === \Smarty\Smarty::SCOPE_LOCAL) {
$this->_updateConfigVarStack($new_config_vars);
$tagScope = 0;
if (!$this->scope) {
return;
}
}
if ($this->parent->_isTplObj() && ($tagScope || $this->parent->scope)) {
$mergedScope = $tagScope | $this->scope;
if ($mergedScope) {
// update scopes
/* @var \Smarty_Internal_Template|\Smarty|Data $ptr */
foreach ($this->parent->_getAffectedScopes($mergedScope) as $ptr) {
$this->_assignConfigVars($ptr->config_vars, $new_config_vars);
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
$this->_updateConfigVarStack($new_config_vars);
}
}
}
}
}
}
/**
* Assign all config variables in given scope
*
* @param array $config_vars config variables in scope
* @param array $new_config_vars loaded config variables
*/
private function _assignConfigVars(&$config_vars, $new_config_vars)
{
// copy global config vars
foreach ($new_config_vars[ 'vars' ] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($config_vars[ $variable ])) {
$config_vars[ $variable ] = $value;
} else {
$config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value);
}
}
// scan sections
$sections = $this->source->config_sections;
if (!empty($sections)) {
foreach ((array)$sections as $tpl_section) {
if (isset($new_config_vars[ 'sections' ][ $tpl_section ])) {
foreach ($new_config_vars[ 'sections' ][ $tpl_section ][ 'vars' ] as $variable => $value) {
if ($this->smarty->config_overwrite || !isset($config_vars[ $variable ])) {
$config_vars[ $variable ] = $value;
} else {
$config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value);
}
}
}
}
}
}
/**
* Update config variables in template local variable stack
*
* @param array $config_vars
*/
private function _updateConfigVarStack($config_vars)
{
$i = 0;
while (isset($this->_var_stack[ $i ])) {
$this->_assignConfigVars($this->_var_stack[ $i ][ 'config' ], $config_vars);
$i++;
}
}
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
* configuration
*
* @return bool
* @throws \SmartyException
*/
public function mustCompile()
{
if (!$this->source->exists) {
if ($this->_isSubTpl()) {
$parent_resource = " in '{$this->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->handler->uncompiled &&
($this->smarty->force_compile || $this->source->handler->recompiled ||
!$this->compiled->exists || ($this->compile_check &&
$this->compiled->getTimeStamp() <
$this->source->getTimeStamp())));
}
return $this->mustCompile;
}
/**
* Update new assigned template or config variable in other effected scopes
*
* @param string|null $varName variable name
* @param int $tagScope tag scope to which bubble up variable value
*/
protected function _updateScope($varName, $tagScope = 0)
{
if ($tagScope) {
$this->_updateVarStack($this, $varName);
$tagScope = $tagScope & ~\Smarty\Smarty::SCOPE_LOCAL;
if (!$this->scope && !$tagScope) {
return;
}
}
$mergedScope = $tagScope | $this->scope;
if ($mergedScope) {
if ($mergedScope & \Smarty\Smarty::SCOPE_GLOBAL && $varName) {
\Smarty\Smarty::$global_tpl_vars[ $varName ] = $this->tpl_vars[ $varName ];
}
// update scopes
foreach ($this->_getAffectedScopes($mergedScope) as $ptr) {
$this->_updateVariableInOtherScope($ptr->tpl_vars, $varName);
if ($tagScope && $ptr->_isTplObj() && isset($this->_var_stack)) {
$this->_updateVarStack($ptr, $varName);
}
}
}
}
/**
* Get array of objects which needs to be updated by given scope value
*
* @param int $mergedScope merged tag and template scope to which bubble up variable value
*
* @return array
*/
private function _getAffectedScopes($mergedScope)
{
$_stack = array();
$ptr = $this->parent;
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$mergedScope = $mergedScope & ~\Smarty\Smarty::SCOPE_PARENT;
if (!$mergedScope) {
// only parent was set, we are done
return $_stack;
}
$ptr = $ptr->parent;
}
while (isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$ptr = $ptr->parent;
}
if ($mergedScope & \Smarty\Smarty::SCOPE_SMARTY) {
if (isset($this->smarty)) {
$_stack[] = $this->smarty;
}
} elseif ($mergedScope & \Smarty\Smarty::SCOPE_ROOT) {
while (isset($ptr)) {
if (!$ptr->_isTplObj()) {
$_stack[] = $ptr;
break;
}
$ptr = $ptr->parent;
}
}
return $_stack;
}
/**
* Update variable in other scope
*
* @param array $tpl_vars template variable array
* @param string $varName variable name
*/
private function _updateVariableInOtherScope(&$tpl_vars, $varName)
{
if (!isset($tpl_vars[ $varName ])) {
$tpl_vars[ $varName ] = clone $this->tpl_vars[ $varName ];
} else {
$tpl_vars[ $varName ] = clone $tpl_vars[ $varName ];
$tpl_vars[ $varName ]->value = $this->tpl_vars[ $varName ]->value;
}
}
/**
* Update variable in template local variable stack
*
* @param \Smarty_Internal_Template $tpl
* @param string|null $varName variable name or null for config variables
*/
private function _updateVarStack(Smarty_Internal_Template $tpl, $varName)
{
$i = 0;
while (isset($tpl->_var_stack[ $i ])) {
$this->_updateVariableInOtherScope($tpl->_var_stack[ $i ][ 'tpl' ], $varName);
$i++;
}
}
}

View File

@@ -1,927 +0,0 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Base
* This file contains the basic shared methods for template handling
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
use Smarty\Cacheresource\Base;
use Smarty\Data;
use Smarty\Smarty;
/**
* Class with shared smarty/template methods
*
* @property int $_objType
*
*/
abstract class Smarty_Internal_TemplateBase extends Data
{
/**
* Set this if you want different sets of cache files for the same
* templates.
*
* @var string
*/
public $cache_id = null;
/**
* Set this if you want different sets of compiled files for the same
* templates.
*
* @var string
*/
public $compile_id = null;
/**
* caching enabled
*
* @var int
*/
public $caching = \Smarty\Smarty::CACHING_OFF;
/**
* check template for modifications?
*
* @var int
*/
public $compile_check = \Smarty\Smarty::COMPILECHECK_ON;
/**
* cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 3600;
/**
* Array of source information for known template functions
*
* @var array
*/
public $tplFunctions = array();
/**
* When initialized to an (empty) array, this variable will hold a stack of template variables.
*
* @var null|array
*/
public $_var_stack = null;
/**
* Valid filter types
*
* @var array
*/
private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @throws Exception
* @throws SmartyException
* @return string rendered template output
*/
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
return $result === null ? ob_get_clean() : $result;
}
/**
* displays a Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @throws \Exception
* @throws \SmartyException
*/
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
// display template
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
}
/**
* test if cache is valid
*
* @api Smarty::isCached()
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
*
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template
* object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return bool cache status
* @throws \Exception
* @throws \SmartyException
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
}
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
*
* @return mixed
* @throws \Exception
* @throws \SmartyException
*/
private function _execute($template, $cache_id, $compile_id, $parent, $function)
{
$smarty = $this->_getSmartyObj();
$saveVars = true;
if ($template === null) {
if (!$this->_isTplObj()) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = $this;
}
} elseif (is_object($template)) {
/* @var Smarty_Internal_Template $template */
if (!isset($template->_objType) || !$template->_isTplObj()) {
throw new SmartyException($function . '():Template object expected');
}
} else {
// get template object
$saveVars = false;
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false);
if ($this->_objType === 1) {
// set caching in template object
$template->caching = $this->caching;
}
}
// make sure we have integer values
$template->caching = (int)$template->caching;
// fetch template content
$level = ob_get_level();
try {
$_smarty_old_error_level =
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;
if ($smarty->isMutingUndefinedOrNullWarnings()) {
$errorHandler = new \Smarty\ErrorHandler();
$errorHandler->activate();
}
if ($this->_objType === 2) {
/* @var Smarty_Internal_Template $this */
$template->tplFunctions = $this->tplFunctions;
$template->inheritance = $this->inheritance;
}
/* @var Smarty_Internal_Template $parent */
if (isset($parent->_objType) && ($parent->_objType === 2) && !empty($parent->tplFunctions)) {
$template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions);
}
if ($function === 2) {
if ($template->caching) {
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
$result = $template->cached->isCached($template);
Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template;
} else {
return false;
}
} else {
if ($saveVars) {
$savedTplVars = $template->tpl_vars;
$savedConfigVars = $template->config_vars;
}
ob_start();
$template->_mergeVars();
if (!empty(\Smarty\Smarty::$global_tpl_vars)) {
$template->tpl_vars = array_merge(\Smarty\Smarty::$global_tpl_vars, $template->tpl_vars);
}
$result = $template->render(false, $function);
$template->_cleanUp();
if ($saveVars) {
$template->tpl_vars = $savedTplVars;
$template->config_vars = $savedConfigVars;
} else {
if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) {
$template->parent = null;
$template->tpl_vars = $template->config_vars = array();
Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template;
}
}
}
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
return $result;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
if (isset($errorHandler)) {
$errorHandler->deactivate();
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
throw $e;
}
}
/**
* Registers plugin to be used in templates
*
* @api Smarty::registerPlugin()
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl
*
* @param string $type plugin type
* @param string $name name of template tag
* @param callable $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
{
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
throw new SmartyException("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin '{$name}' not callable");
} elseif ($cacheable && $cache_attr) {
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
} else {
$smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool)$cacheable, (array)$cache_attr);
}
return $this;
}
/**
* Registers plugin to be used in templates
*
* @api Smarty::unregisterPlugin()
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
*
* @param string $type plugin type
* @param string $name name of template tag
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterPlugin($type, $name)
{
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
unset($smarty->registered_plugins[ $type ][ $name ]);
}
return $this;
}
/**
* load a filter of specified type and name
*
* @api Smarty::loadFilter()
* @link https://www.smarty.net/docs/en/api.load.filter.tpl
*
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws \SmartyException
*/
public function loadFilter($type, $name)
{
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if (is_callable($_plugin)) {
$smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
return true;
}
if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute');
}
if (is_callable($_plugin)) {
$smarty->registered_filters[ $type ][ $_filter_name ] = $_plugin;
return true;
}
throw new SmartyException("{$type}filter '{$name}' not found or callable");
}
/**
* load a filter of specified type and name
*
* @api Smarty::unloadFilter()
*
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl
*
* @param string $type filter type
* @param string $name filter name
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
*/
public function unloadFilter($type, $name)
{
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[ $type ])) {
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($smarty->registered_filters[ $type ][ $_filter_name ])) {
unset($smarty->registered_filters[ $type ][ $_filter_name ]);
if (empty($smarty->registered_filters[ $type ])) {
unset($smarty->registered_filters[ $type ]);
}
}
}
return $this;
}
/**
* Registers a filter function
*
* @param string $type filter type
* @param callable $callback
* @param string|null $name optional filter name
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
*@link https://www.smarty.net/docs/en/api.register.filter.tpl
*
* @api Smarty::registerFilter()
*/
public function registerFilter($type, $callback, $name = null)
{
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) {
throw new SmartyException("{$type}filter '{$name}' not callable");
}
$smarty->registered_filters[ $type ][ $name ] = $callback;
return $this;
}
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback|string $callback
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
*@api Smarty::unregisterFilter()
*
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
*
*/
public function unregisterFilter($type, $callback)
{
$smarty = $this->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[ $type ])) {
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);
if (isset($smarty->registered_filters[ $type ][ $name ])) {
unset($smarty->registered_filters[ $type ][ $name ]);
if (empty($smarty->registered_filters[ $type ])) {
unset($smarty->registered_filters[ $type ]);
}
}
}
return $this;
}
/**
* Registers object to be used in templates
*
* @api Smarty::registerObject()
* @link https://www.smarty.net/docs/en/api.register.object.tpl
*
* @param string $object_name
* @param object $object the referenced PHP object to register
* @param array $allowed_methods_properties list of allowed methods (empty = all)
* @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function registerObject(
$object_name,
$object,
$allowed_methods_properties = array(),
$format = true,
$block_methods = array()
) {
$smarty = $this->_getSmartyObj();
// test if allowed methods callable
if (!empty($allowed_methods_properties)) {
foreach ((array)$allowed_methods_properties as $method) {
if (!is_callable(array($object, $method)) && !property_exists($object, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array)$block_methods as $method) {
if (!is_callable(array($object, $method))) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty->registered_objects[ $object_name ] =
array($object, (array)$allowed_methods_properties, (boolean)$format, (array)$block_methods);
return $this;
}
/**
* Registers plugin to be used in templates
*
* @param string $object_name name of object
*
* @return Smarty_Internal_TemplateBase
* @api Smarty::unregisterObject()
* @link https://www.smarty.net/docs/en/api.unregister.object.tpl
*
*/
public function unregisterObject($object_name)
{
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_objects[ $object_name ])) {
unset($smarty->registered_objects[ $object_name ]);
}
return $this;
}
/**
* @param int $compile_check
*/
public function setCompileCheck($compile_check)
{
$this->compile_check = (int)$compile_check;
}
/**
* @param int $caching
*/
public function setCaching($caching)
{
$this->caching = (int)$caching;
}
/**
* @param int $cache_lifetime
*/
public function setCacheLifetime($cache_lifetime)
{
$this->cache_lifetime = $cache_lifetime;
}
/**
* @param string $compile_id
*/
public function setCompileId($compile_id)
{
$this->compile_id = $compile_id;
}
/**
* @param string $cache_id
*/
public function setCacheId($cache_id)
{
$this->cache_id = $cache_id;
}
/**
* Add default modifiers
*
* @api Smarty::addDefaultModifiers()
*
* @param array|string $modifiers modifier or list of modifiers
* to add
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function addDefaultModifiers($modifiers)
{
$smarty = $this->_getSmartyObj();
if (is_array($modifiers)) {
$smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {
$smarty->default_modifiers[] = $modifiers;
}
return $this;
}
/**
* creates a data object
*
* @param Data|null $parent next higher level of Smarty
* variables
* @param null $name optional data block name
*
* @return Smarty_Data data object
* @throws SmartyException
* @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
*
*/
public function createData(Data $parent = null, $name = null)
{
/* @var Smarty $smarty */
$smarty = $this->_getSmartyObj();
$dataObj = new Smarty_Data($parent, $smarty, $name);
if ($smarty->debugging) {
\Smarty\Debug::register_data($dataObj);
}
return $dataObj;
}
/**
* return name of debugging template
*
* @api Smarty::getDebugTemplate()
*
* @return string
*/
public function getDebugTemplate()
{
$smarty = $this->_getSmartyObj();
return $smarty->debug_tpl;
}
/**
* Get default modifiers
*
* @api Smarty::getDefaultModifiers()
*
* @return array list of default modifiers
*/
public function getDefaultModifiers()
{
$smarty = $this->_getSmartyObj();
return $smarty->default_modifiers;
}
/**
* return a reference to a registered object
*
* @api Smarty::getRegisteredObject()
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
*
* @param string $object_name object name
*
* @return object
* @throws \SmartyException if no such object is found
*/
public function getRegisteredObject($object_name)
{
$smarty = $this->_getSmartyObj();
if (!isset($smarty->registered_objects[ $object_name ])) {
throw new SmartyException("'$object_name' is not a registered object");
}
if (!is_object($smarty->registered_objects[ $object_name ][ 0 ])) {
throw new SmartyException("registered '$object_name' is not an object");
}
return $smarty->registered_objects[ $object_name ][ 0 ];
}
/**
* Get literals
*
* @api Smarty::getLiterals()
*
* @return array list of literals
*/
public function getLiterals()
{
$smarty = $this->_getSmartyObj();
return (array)$smarty->literals;
}
/**
* Add literals
*
* @param array|string $literals literal or list of literals
* to addto add
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
* @api Smarty::addLiterals()
*
*/
public function addLiterals($literals = null)
{
if (isset($literals)) {
$this->_setLiterals($this->_getSmartyObj(), (array)$literals);
}
return $this;
}
/**
* Set literals
*
* @param array|string $literals literal or list of literals
* to setto set
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
* @api Smarty::setLiterals()
*
*/
public function setLiterals($literals = null)
{
$smarty = $this->_getSmartyObj();
$smarty->literals = array();
if (!empty($literals)) {
$this->_setLiterals($smarty, (array)$literals);
}
return $this;
}
/**
* common setter for literals for easier handling of duplicates the
* Smarty::$literals array gets filled with identical key values
*
* @param Smarty $smarty
* @param array $literals
*
* @throws \SmartyException
*/
private function _setLiterals(Smarty $smarty, $literals)
{
$literals = array_combine($literals, $literals);
$error = isset($literals[ $smarty->left_delimiter ]) ? array($smarty->left_delimiter) : array();
$error = isset($literals[ $smarty->right_delimiter ]) ? $error[] = $smarty->right_delimiter : $error;
if (!empty($error)) {
throw new SmartyException(
'User defined literal(s) "' . $error .
'" may not be identical with left or right delimiter'
);
}
$smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
}
/**
* Check if filter type is valid
*
* @param string $type
*
* @throws \SmartyException
*/
private function _checkFilterType($type)
{
if (!isset($this->filterTypes[ $type ])) {
throw new SmartyException("Illegal filter type '{$type}'");
}
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
private function _getFilterName($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[ 0 ]) ? get_class($function_name[ 0 ]) : $function_name[ 0 ]);
return $_class_name . '_' . $function_name[ 1 ];
} elseif (is_string($function_name)) {
return $function_name;
} else {
return 'closure';
}
}
/**
* Registers static classes to be used in templates
*
* @param string $class_name
* @param string $class_impl the referenced PHP class to
* register
*
* @return Smarty_Internal_TemplateBase
* @throws \SmartyException
*@api Smarty::registerClass()
* @link https://www.smarty.net/docs/en/api.register.class.tpl
*
*/
public function registerClass($class_name, $class_impl)
{
$smarty = $this->_getSmartyObj();
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");
}
// register the class
$smarty->registered_classes[ $class_name ] = $class_impl;
return $this;
}
/**
* Registers a resource to fetch a template
*
* @param string $name name of resource type
* @param Base $resource_handler
*
* @return Smarty_Internal_TemplateBase
* @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
*
* @api Smarty::registerCacheResource()
*/
public function registerCacheResource($name, Base $resource_handler) {
$smarty = $this->_getSmartyObj();
$smarty->registered_cache_resources[ $name ] = $resource_handler;
return $this;
}
/**
* Unregisters a resource to fetch a template
*
* @api Smarty::unregisterCacheResource()
* @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
*
* @param $name
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function unregisterCacheResource($name)
{
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_cache_resources[ $name ])) {
unset($smarty->registered_cache_resources[ $name ]);
}
return $this;
}
/**
* Register config default handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_TemplateBase
* @throws SmartyException if $callback is not callable
*@api Smarty::registerDefaultConfigHandler()
*
*/
public function registerDefaultConfigHandler($callback)
{
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException('Default config handler not callable');
}
return $this;
}
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_TemplateBase
* @throws SmartyException if $callback is not callable
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
*
* @api Smarty::registerDefaultPluginHandler()
*/
public function registerDefaultPluginHandler($callback)
{
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $this;
}
/**
* Register template default handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_TemplateBase
* @throws SmartyException if $callback is not callable
* @api Smarty::registerDefaultTemplateHandler()
*
*/
public function registerDefaultTemplateHandler($callback)
{
$smarty = $this->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException('Default template handler not callable');
}
return $this;
}
/**
* Registers a resource to fetch a template
*
* @api Smarty::registerResource()
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
*
* @param string $name name of resource type
* @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base
*
* @return \Smarty|\Smarty_Internal_Template
*/
public function registerResource($name, Smarty\Resource\Base $resource_handler)
{
$smarty = $this->_getSmartyObj();
$smarty->registered_resources[ $name ] = $resource_handler;
return $this;
}
/**
* Unregisters a resource to fetch a template
*
* @param string $type name of resource type
*
* @return Smarty_Internal_TemplateBase
* @api Smarty::unregisterResource()
* @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
*
*/
public function unregisterResource($type)
{
$smarty = $this->_getSmartyObj();
if (isset($smarty->registered_resources[ $type ])) {
unset($smarty->registered_resources[ $type ]);
}
return $this;
}
/**
* set the debug template
*
* @param string $tpl_name
*
* @return Smarty_Internal_TemplateBase
* @throws SmartyException if file is not readable
*@api Smarty::setDebugTemplate()
*
*/
public function setDebugTemplate($tpl_name)
{
$smarty = $this->_getSmartyObj();
if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'");
}
$smarty->debug_tpl = $tpl_name;
return $this;
}
/**
* Set default modifiers
*
* @param array|string $modifiers modifier or list of modifiers
* to set
*
* @return Smarty_Internal_TemplateBase
* @api Smarty::setDefaultModifiers()
*
*/
public function setDefaultModifiers($modifiers)
{
$smarty = $this->_getSmartyObj();
$smarty->default_modifiers = (array)$modifiers;
return $this;
}
}

View File

@@ -8,6 +8,8 @@
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for the Smarty data object
* The Smarty data object will hold Smarty variables in the current scope
@@ -42,7 +44,7 @@ class Smarty_Data extends \Smarty\Data
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty|Smarty_Internal_Template $smarty global smarty instance
* @param Smarty|Template $smarty global smarty instance
* @param string $name optional data block name
*
* @throws SmartyException

View File

@@ -16,6 +16,8 @@
* as this would lead to (severe) performance penalty! how should this be handled?
*/
use Smarty\Template;
/**
* This class does contain the security settings
*/
@@ -670,9 +672,9 @@ class Smarty_Security
/**
* Register callback functions call at start/end of template rendering
*
* @param \Smarty_Internal_Template $template
* @param \Smarty\Template $template
*/
public function registerCallBacks(Smarty_Internal_Template $template)
public function registerCallBacks(Template $template)
{
$template->startRenderCallbacks[] = array($this, 'startTemplate');
$template->endRenderCallbacks[] = array($this, 'endTemplate');

View File

@@ -4,6 +4,9 @@
*
*/
use Smarty\TemplateBase;
use Smarty\Template;
/**
* Smarty Test Case Fixture
*/
@@ -352,7 +355,7 @@ KEY `name` (`name`)
/**
* Return source path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
* @param null|string $dir optional template folder
@@ -384,7 +387,7 @@ KEY `name` (`name`)
/**
* Build template uid
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param TemplateBase $tpl template object
* @param null|string $value
* @param null|string $name optional template name
* @param null|string $type optional template type
@@ -457,13 +460,13 @@ KEY `name` (`name`)
/**
* Return base name
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
* @param null|string $name optional template name
* @param null|string $type optional template type
*
* @return null|string
*/
public function getBasename(Smarty_Internal_Template $tpl, $name = null, $type = null)
public function getBasename(Template $tpl, $name = null, $type = null)
{
$name = isset($name) ? $name : $tpl->source->name;
$type = isset($type) ? $type : $tpl->source->type;
@@ -487,7 +490,7 @@ KEY `name` (`name`)
/**
* Return compiled file path
*
* @param \Smarty_Internal_Template|\Smarty_Internal_TemplateBase $tpl template object
* @param \Smarty\Template|\Smarty\TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param bool $caching caching flag
* @param null|string $compile_id optional compile id
@@ -498,7 +501,7 @@ KEY `name` (`name`)
* @return string
* @throws \Exception
*/
public function buildCompiledPath(Smarty_Internal_Template $tpl, $sub = true, $caching = false, $compile_id = null,
public function buildCompiledPath(Template $tpl, $sub = true, $caching = false, $compile_id = null,
$name = null, $type = null, $dir = null)
{
$sep = DIRECTORY_SEPARATOR;
@@ -546,7 +549,7 @@ KEY `name` (`name`)
/**
* Return cache file path
*
* @param Smarty_Internal_TemplateBase $tpl template object
* @param TemplateBase $tpl template object
* @param bool $sub use sub directory flag
* @param null|string $cache_id optional cache id
* @param null|string $compile_id optional compile id
@@ -618,11 +621,11 @@ KEY `name` (`name`)
* prefilter to insert test number
*
* @param string $source
* @param \Smarty_Internal_Template $tpl
* @param \Smarty\Template $tpl
*
* @return string
*/
public function prefilterTest($source, Smarty_Internal_Template $tpl)
public function prefilterTest($source, Template $tpl)
{
return str_replace('#test#', "test:{\$test nocache} compiled:{$tpl->getTemplateVars('test')} rendered:{\$test}",
$source);

View File

@@ -6,6 +6,8 @@
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for cache resource file tests
*
@@ -28,7 +30,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
$this->assertEquals($a, $b);
}
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
public function compiledPrefilter($text, Template $tpl)
{
$replace = $tpl->getTemplateVars('test');
return str_replace('#', $replace ?? '', $text);

View File

@@ -1,12 +1,15 @@
<?php
use Smarty\Template;
use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.apc.php';
class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
{
public $lockTime = 0;
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;
@@ -17,7 +20,7 @@ class Smarty_CacheResource_Apctest extends Smarty_CacheResource_Apc
return parent::hasLock($smarty, $cached);
}
public function get(Smarty_Internal_Template $_template)
public function get(Template $_template)
{
$this->contents = array();
$this->timestamps = array();

View File

@@ -5,7 +5,7 @@ class Smarty_CacheResource_Filetest extends \Smarty\Cacheresource\File
{
public $lockTime = 0;
public function hasLock(\Smarty\Smarty $smarty, \Smarty_Template_Cached $cached)
public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;

View File

@@ -1,12 +1,15 @@
<?php
use Smarty\Template;
use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.memcache.php';
class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
{
public $lockTime = 0;
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;
@@ -17,7 +20,7 @@ class Smarty_CacheResource_Memcachetest extends Smarty_CacheResource_Memcache
return parent::hasLock($smarty, $cached);
}
public function get(Smarty_Internal_Template $_template)
public function get(Template $_template)
{
$this->contents = array();
$this->timestamps = array();

View File

@@ -1,5 +1,7 @@
<?php
use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.mysql.php';
class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
@@ -18,7 +20,7 @@ class Smarty_CacheResource_Mysqltest extends Smarty_CacheResource_Mysql
VALUES (:id, :name, :cache_id, :compile_id, :content)');
}
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;

View File

@@ -1,12 +1,14 @@
<?php
use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo_gzip.php';
class Smarty_CacheResource_Pdo_Gziptest extends Smarty_CacheResource_Pdo_Gzip
{
public $lockTime = 0;
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;

View File

@@ -1,5 +1,7 @@
<?php
use Smarty\Template\Cached;
require_once SMARTY_DIR . '../demo/plugins/cacheresource.pdo.php';
class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo
@@ -7,7 +9,7 @@ class Smarty_CacheResource_Pdotest extends Smarty_CacheResource_Pdo
public $lockTime = 0;
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
public function hasLock(Smarty $smarty, Cached $cached)
{
if ($this->lockTime) {
$this->lockTime--;

View File

@@ -1,16 +1,18 @@
<?php
use Smarty\Resource\FilePlugin;
use Smarty\Template;
use Smarty\Template\Source;
class Smarty_Resource_FiletestPlugin extends FilePlugin
{
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
parent::populate($source, $_template);
if ($source->exists) {

View File

@@ -10,9 +10,12 @@
* -------------------------------------------------------------
*/
use Smarty\Template;
use Smarty\Template\Source;
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
{
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$source->filepath = 'db4:';
$source->uid = sha1($source->resource);
@@ -20,7 +23,7 @@ class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source)
public function getContent(Source $source)
{
return "foo = 'bar'\n";
}

View File

@@ -1,6 +1,8 @@
<?php
use Smarty\Resource\FilePlugin;
use Smarty\Template;
use Smarty\Template\Source;
/**
* Ambiguous Filename Custom Resource Example
@@ -40,10 +42,10 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @param Source $source source object
* @param Template $_template template object
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$segment = '';
if ($this->segment) {

View File

@@ -6,6 +6,8 @@
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for extends resource tests
*
@@ -27,7 +29,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
$this->cleanDirs();
}
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
public function compiledPrefilter($text, Template $tpl)
{
return str_replace('#', $tpl->getTemplateVars('test'), $text);
}

View File

@@ -11,17 +11,19 @@
*/
use Smarty\Resource\RecompiledPlugin;
use Smarty\Template;
use Smarty\Template\Source;
class _DbPlugin extends RecompiledPlugin {
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
public function populate(Source $source, Template $_template = null) {
$source->filepath = 'db:';
$source->uid = sha1($source->resource);
$source->timestamp = 1000000000;
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source) {
public function getContent(Source $source) {
return '{$x="hello world"}{$x}';
}
}

View File

@@ -11,10 +11,12 @@
*/
use Smarty\Resource\RecompiledPlugin;
use Smarty\Template;
use Smarty\Template\Source;
class _Db2Plugin extends RecompiledPlugin
{
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$source->filepath = 'db2:';
$source->uid = sha1($source->resource);
@@ -22,7 +24,7 @@ class _Db2Plugin extends RecompiledPlugin
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source)
public function getContent(Source $source)
{
return '{$x="hello world"}{$x}';
}

View File

@@ -10,9 +10,12 @@
* -------------------------------------------------------------
*/
use Smarty\Template;
use Smarty\Template\Source;
class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
{
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$source->filepath = 'db3:';
$source->uid = sha1($source->resource);
@@ -20,12 +23,12 @@ class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source)
public function getContent(Source $source)
{
return '{$x="hello world"}{$x}';
}
public function getCompiledFilepath(Smarty_Internal_Template $_template)
public function getCompiledFilepath(Template $_template)
{
return false;
}

View File

@@ -10,9 +10,12 @@
* -------------------------------------------------------------
*/
use Smarty\Template;
use Smarty\Template\Source;
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
{
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
public function populate(Source $source, Template $_template = null)
{
$source->filepath = 'db4:';
$source->uid = sha1($source->resource);
@@ -20,7 +23,7 @@ class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
$source->exists = true;
}
public function getContent(Smarty_Template_Source $source)
public function getContent(Source $source)
{
if ($source->is_config) {
return "foo = 'bar'\n";

View File

@@ -5,17 +5,20 @@
* @package Smarty
* @subpackage PHPunitPlugin
*/
use Smarty\Template;
/**
* Smarty {testparameter}{/testparameter} block plugin
*
* @param array $params parameter array
* @param string $content contents of the block
* @param \Smarty_Internal_Template $template template object
* @param \Smarty\Template $template template object
* @param bool $repeat flag
*
* @return string content re-formatted
*/
function smarty_block_testparameter($params, $content, Smarty_Internal_Template $template, &$repeat)
function smarty_block_testparameter($params, $content, Template $template, &$repeat)
{
if (isset($content)) {
return $content;

View File

@@ -6,6 +6,8 @@
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for block extends compiler tests
*
@@ -21,7 +23,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
//$this->smarty->setMergeCompiledIncludes(true);
}
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
public function compiledPrefilter($text, Template $tpl)
{
return str_replace('#', $tpl->getTemplateVars('test'), $text);
}
@@ -1096,7 +1098,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
*/
public function testPostFilter_031()
{
function smarty_postfilter_test031($compiled, Smarty_Internal_Template $template)
function smarty_postfilter_test031($compiled, Template $template)
{
return str_replace("'foo'", "'bar'", $compiled);
}

View File

@@ -6,6 +6,8 @@
* @subpackage PHPunitPlugin
*/
use Smarty\Template;
/**
* Smarty {checkconfigvar}
*
@@ -24,7 +26,7 @@ function smarty_function_checkconfigvar($params, $template)
$var = $params['var'];
$ptr = $template;
while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
if (in_array('template', $types) && $ptr instanceof Template) {
$output .= "#{$ptr->source->name}:\${$var} =";
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
$ptr = $ptr->parent;

View File

@@ -6,6 +6,8 @@
* @subpackage PHPunitPlugin
*/
use Smarty\Template;
/**
* Smarty {checkvar}
*
@@ -24,7 +26,7 @@ function smarty_function_checkvar($params, $template)
$var = $params['var'];
$ptr = $template;
while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
if (in_array('template', $types) && $ptr instanceof Template) {
$output .= "#{$ptr->source->name}:\${$var} =";
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
$i = 0;

View File

@@ -6,6 +6,8 @@
* @subpackage PHPunitPlugin
*/
use Smarty\Template;
/**
* Smarty {gatparams}
*
@@ -14,7 +16,7 @@
*
* @return string
*/
function smarty_function_getparams($params, Smarty_Internal_Template $template)
function smarty_function_getparams($params, Template $template)
{
return var_export($params, true);
}

View File

@@ -6,6 +6,8 @@
* @subpackage PHPunitPlugin
*/
use Smarty\Template;
/**
* Smarty {getvar}
*
@@ -14,7 +16,7 @@
*
* @return string
*/
function smarty_function_getvar($params, Smarty_Internal_Template $template)
function smarty_function_getvar($params, Template $template)
{
if (isset($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $template->getTemplateVars($params[ 'var' ]));