mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- optimization get rid of __get and __set in source object
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
===== 3.1.28-dev===== (xx.xx.2015)
|
===== 3.1.28-dev===== (xx.xx.2015)
|
||||||
06.07.2015
|
06.07.2015
|
||||||
- optimize {block} compilation
|
- optimize {block} compilation
|
||||||
|
- optimization get rid of __get and __set in source object
|
||||||
|
|
||||||
01.07.2015
|
01.07.2015
|
||||||
- optimize compile check handling
|
- optimize compile check handling
|
||||||
|
@@ -23,7 +23,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
|||||||
$uid = '';
|
$uid = '';
|
||||||
$sources = array();
|
$sources = array();
|
||||||
$exists = true;
|
$exists = true;
|
||||||
foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
|
foreach ($source->smarty->getTemplateDir() as $key => $directory) {
|
||||||
try {
|
try {
|
||||||
$s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
|
$s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
|
||||||
if (!$s->exists) {
|
if (!$s->exists) {
|
||||||
@@ -38,9 +38,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
|||||||
|
|
||||||
if (!$sources) {
|
if (!$sources) {
|
||||||
$source->exists = false;
|
$source->exists = false;
|
||||||
$source->template = $_template;
|
return;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sources = array_reverse($sources, true);
|
$sources = array_reverse($sources, true);
|
||||||
@@ -52,9 +50,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
|||||||
$source->uid = sha1($uid);
|
$source->uid = sha1($uid);
|
||||||
$source->exists = $exists;
|
$source->exists = $exists;
|
||||||
if ($_template && $_template->smarty->compile_check) {
|
if ($_template && $_template->smarty->compile_check) {
|
||||||
$source->timestamp = $s->timestamp;
|
$source->timestamp = $s->getTimeStamp();
|
||||||
}
|
}
|
||||||
// need the template at getContent()
|
|
||||||
$source->template = $_template;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.28-dev/21';
|
const SMARTY_VERSION = '3.1.28-dev/22';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -151,7 +151,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
|
|||||||
$nextCompiler = $compiler;
|
$nextCompiler = $compiler;
|
||||||
while ($nextCompiler !== $nextCompiler->parent_compiler) {
|
while ($nextCompiler !== $nextCompiler->parent_compiler) {
|
||||||
$nextCompiler = $nextCompiler->parent_compiler;
|
$nextCompiler = $nextCompiler->parent_compiler;
|
||||||
preg_match_all($preg, $nextCompiler->template->source->content, $match, PREG_SET_ORDER);
|
preg_match_all($preg, $nextCompiler->template->source->getContent(), $match, PREG_SET_ORDER);
|
||||||
foreach ($match as $m) {
|
foreach ($match as $m) {
|
||||||
if (isset($m[3]) && !empty($m[3])) {
|
if (isset($m[3]) && !empty($m[3])) {
|
||||||
$itemAttr[strtolower($m[3])] = true;
|
$itemAttr[strtolower($m[3])] = true;
|
||||||
|
@@ -101,15 +101,11 @@ class Smarty_Internal_Config_File_Compiler
|
|||||||
{
|
{
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->name, $this->template->source->getTimeStamp(), $this->template->source->type);
|
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->name, $this->template->source->getTimeStamp(), $this->template->source->type);
|
||||||
// on empty config just return
|
|
||||||
if ($template->source->content == '') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::start_compile($this->template);
|
Smarty_Internal_Debug::start_compile($this->template);
|
||||||
}
|
}
|
||||||
// init the lexer/parser to compile the config file
|
// init the lexer/parser to compile the config file
|
||||||
$lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->content) . "\n", $this);
|
$lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . "\n", $this);
|
||||||
$parser = new $this->parser_class($lex, $this);
|
$parser = new $this->parser_class($lex, $this);
|
||||||
|
|
||||||
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
||||||
|
@@ -21,10 +21,9 @@ class Smarty_Internal_Extension_DefaultTemplateHandler
|
|||||||
* get default content from template of config resource handler
|
* get default content from template of config resource handler
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template
|
* @param Smarty_Internal_Template $_template
|
||||||
* @param Smarty_Internal_Template_Source $source
|
* @param Smarty_Template_Source $source
|
||||||
* @param Smarty_Resource $resObj
|
|
||||||
*/
|
*/
|
||||||
static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj)
|
static function _getDefault(Smarty_Internal_Template $_template, $source)
|
||||||
{
|
{
|
||||||
if ($source->isConfig) {
|
if ($source->isConfig) {
|
||||||
$default_handler = $_template->smarty->default_config_handler_func;
|
$default_handler = $_template->smarty->default_config_handler_func;
|
||||||
|
@@ -39,13 +39,13 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
|||||||
$components = explode('|', $source->name);
|
$components = explode('|', $source->name);
|
||||||
$exists = true;
|
$exists = true;
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
$s = Smarty_Resource::source(null, $source->smarty, $component);
|
$s = Smarty_Template_Source::load(null, $source->smarty, $component);
|
||||||
if ($s->type == 'php') {
|
if ($s->type == 'php') {
|
||||||
throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
|
throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
|
||||||
}
|
}
|
||||||
$sources[$s->uid] = $s;
|
$sources[$s->uid] = $s;
|
||||||
$uid .= $source->smarty->_realpath($s->filepath);
|
$uid .= $source->smarty->_realpath($s->filepath);
|
||||||
if ($_template && $_template->smarty->compile_check) {
|
if ($_template) {
|
||||||
$exists = $exists && $s->exists;
|
$exists = $exists && $s->exists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,11 +53,9 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
|||||||
$source->filepath = $s->filepath;
|
$source->filepath = $s->filepath;
|
||||||
$source->uid = sha1($uid);
|
$source->uid = sha1($uid);
|
||||||
$source->exists = $exists;
|
$source->exists = $exists;
|
||||||
if ($_template && $_template->smarty->compile_check) {
|
if ($_template) {
|
||||||
$source->timestamp = $s->timestamp;
|
$source->timestamp = $s->timestamp;
|
||||||
}
|
}
|
||||||
// need the template at getContent()
|
|
||||||
$source->template = $_template;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +69,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
|||||||
foreach ($source->components as $s) {
|
foreach ($source->components as $s) {
|
||||||
$source->exists = $source->exists && $s->exists;
|
$source->exists = $source->exists && $s->exists;
|
||||||
}
|
}
|
||||||
$source->timestamp = $s->timestamp;
|
$source->timestamp = $source->exists ? $s->getTimeStamp() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +91,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
|||||||
$_content = '';
|
$_content = '';
|
||||||
foreach ($_components as $_component) {
|
foreach ($_components as $_component) {
|
||||||
// read content
|
// read content
|
||||||
$_content .= $_component->content;
|
$_content .= $_component->getContent();
|
||||||
}
|
}
|
||||||
return $_content;
|
return $_content;
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
if ($source->timestamp) {
|
if ($source->exists) {
|
||||||
return file_get_contents($source->filepath);
|
return file_get_contents($source->filepath);
|
||||||
}
|
}
|
||||||
if ($source instanceof Smarty_Template_Config) {
|
if ($source instanceof Smarty_Template_Config) {
|
||||||
|
@@ -43,7 +43,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
|
|||||||
*/
|
*/
|
||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
if ($source->timestamp) {
|
if ($source->exists) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||||
|
@@ -76,12 +76,13 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
|
|||||||
public function getContent(Smarty_Template_Source $source)
|
public function getContent(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
// return template string
|
// return template string
|
||||||
$t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty));
|
$content = null;
|
||||||
|
$t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$content, $source->smarty));
|
||||||
if (is_bool($t) && !$t) {
|
if (is_bool($t) && !$t) {
|
||||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $source->content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -613,7 +613,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
} elseif ($_file_to_check[2] == 'string') {
|
} elseif ($_file_to_check[2] == 'string') {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
$source = Smarty_Resource::source(null, $this->smarty, $_file_to_check[0]);
|
$source = Smarty_Template_Source::load(null, $this->smarty, $_file_to_check[0]);
|
||||||
$mtime = $source->getTimeStamp();
|
$mtime = $source->getTimeStamp();
|
||||||
}
|
}
|
||||||
if (!$mtime || $mtime > $_file_to_check[1]) {
|
if (!$mtime || $mtime > $_file_to_check[1]) {
|
||||||
|
@@ -84,7 +84,6 @@ abstract class Smarty_Resource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load template's source into current template object
|
* Load template's source into current template object
|
||||||
* {@internal The loaded source is assigned to $_template->source->content directly.}}
|
|
||||||
*
|
*
|
||||||
* @param Smarty_Template_Source $source source object
|
* @param Smarty_Template_Source $source source object
|
||||||
*
|
*
|
||||||
|
@@ -225,6 +225,7 @@ class Smarty_Template_Compiled
|
|||||||
}
|
}
|
||||||
// call compiler
|
// call compiler
|
||||||
try {
|
try {
|
||||||
|
$_template->loadCompiler();
|
||||||
$code = $_template->compiler->compileTemplate($_template);
|
$code = $_template->compiler->compileTemplate($_template);
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
|
@@ -110,7 +110,7 @@ class Smarty_Template_Config extends Smarty_Template_Source
|
|||||||
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name);
|
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name);
|
||||||
$resource->populate($source, $_template);
|
$resource->populate($source, $_template);
|
||||||
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_config_handler_func)) {
|
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_config_handler_func)) {
|
||||||
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resource);
|
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source);
|
||||||
}
|
}
|
||||||
$source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true);
|
$source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true);
|
||||||
return $source;
|
return $source;
|
||||||
|
@@ -76,6 +76,7 @@ class Smarty_Template_Source
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $filepath = null;
|
public $filepath = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source Timestamp
|
* Source Timestamp
|
||||||
*
|
*
|
||||||
@@ -89,6 +90,7 @@ class Smarty_Template_Source
|
|||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
public $exists = false;
|
public $exists = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source File Base name
|
* Source File Base name
|
||||||
*
|
*
|
||||||
@@ -116,12 +118,14 @@ class Smarty_Template_Source
|
|||||||
* @var Smarty
|
* @var Smarty
|
||||||
*/
|
*/
|
||||||
public $smarty = null;
|
public $smarty = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource is source
|
* Resource is source
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $isConfig = false;
|
public $isConfig = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source is bypassing compiler
|
* Source is bypassing compiler
|
||||||
*
|
*
|
||||||
@@ -135,6 +139,7 @@ class Smarty_Template_Source
|
|||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
public $recompiled = false;
|
public $recompiled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache for Smarty_Template_Compiled instances
|
* cache for Smarty_Template_Compiled instances
|
||||||
*
|
*
|
||||||
@@ -142,6 +147,13 @@ class Smarty_Template_Source
|
|||||||
*/
|
*/
|
||||||
public $compileds = array();
|
public $compileds = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template source content eventually set by default handler
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $content = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create Source Object container
|
* create Source Object container
|
||||||
*
|
*
|
||||||
@@ -205,15 +217,14 @@ class Smarty_Template_Source
|
|||||||
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name);
|
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name);
|
||||||
$resource->populate($source, $_template);
|
$resource->populate($source, $_template);
|
||||||
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_template_handler_func)) {
|
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_template_handler_func)) {
|
||||||
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resObj);
|
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source);
|
||||||
}
|
}
|
||||||
// on recompiling resources we are done
|
// on recompiling resources we are done
|
||||||
if ($smarty->resource_caching && !$resource->recompiled) {
|
if ($smarty->resource_caching && !$resource->recompiled) {
|
||||||
// may by we have already $unique_resource
|
// may by we have already $unique_resource
|
||||||
$is_relative = false;
|
$is_relative = false;
|
||||||
if (!isset($unique_resource)) {
|
if (!isset($unique_resource)) {
|
||||||
$is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') &&
|
$is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') && ($type == 'file' || (isset($_template->parent->source) && $_template->parent->source->type == 'extends'));
|
||||||
($type == 'file' || (isset($_template->parent->source) && $_template->parent->source->type == 'extends'));
|
|
||||||
$unique_resource = $resource->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name);
|
$unique_resource = $resource->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name);
|
||||||
}
|
}
|
||||||
$source->unique_resource = $unique_resource;
|
$source->unique_resource = $unique_resource;
|
||||||
@@ -229,6 +240,9 @@ class Smarty_Template_Source
|
|||||||
* render the uncompiled source
|
* render the uncompiled source
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $_template template object
|
* @param Smarty_Internal_Template $_template template object
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function renderUncompiled(Smarty_Internal_Template $_template)
|
public function renderUncompiled(Smarty_Internal_Template $_template)
|
||||||
{
|
{
|
||||||
@@ -251,52 +265,21 @@ class Smarty_Template_Source
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getTimeStamp() {
|
public function getTimeStamp()
|
||||||
|
{
|
||||||
if (!isset($this->timestamp)) {
|
if (!isset($this->timestamp)) {
|
||||||
$this->handler->populateTimestamp($this);
|
$this->handler->populateTimestamp($this);
|
||||||
}
|
}
|
||||||
return $this->timestamp;
|
return $this->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <<magic>> Generic Setter.
|
* Get source content
|
||||||
*
|
*
|
||||||
* @param string $property_name valid: timestamp, exists, content, template
|
* @return string
|
||||||
* @param mixed $value new value (is not checked)
|
|
||||||
*
|
|
||||||
* @throws SmartyException if $property_name is not valid
|
|
||||||
*/
|
*/
|
||||||
public function __set($property_name, $value)
|
public function getContent()
|
||||||
{
|
{
|
||||||
switch ($property_name) {
|
return isset($this->content) ? $this->content : $this->handler->getContent($this);
|
||||||
// regular attributes
|
|
||||||
case 'content':
|
|
||||||
// required for extends: only
|
|
||||||
case 'template':
|
|
||||||
$this->$property_name = $value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new SmartyException("source property '$property_name' does not exist.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <<magic>> Generic getter.
|
|
||||||
*
|
|
||||||
* @param string $property_name valid: timestamp, exists, content
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
* @throws SmartyException if $property_name is not valid
|
|
||||||
*/
|
|
||||||
public function __get($property_name)
|
|
||||||
{
|
|
||||||
switch ($property_name) {
|
|
||||||
case 'content':
|
|
||||||
return $this->content = $this->handler->getContent($this);
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new SmartyException("source property '$property_name' does not exist.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user