Update to Smarty 3.1.15

This commit is contained in:
Némunaire 2013-10-09 19:08:38 +02:00
commit 1c9cd9208f
119 changed files with 5232 additions and 4641 deletions

View file

@ -15,7 +15,8 @@
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource {
abstract class Smarty_Resource
{
/**
* cache for Smarty_Template_Source instances
* @var array
@ -67,19 +68,19 @@ abstract class Smarty_Resource {
*
* {@internal The loaded source is assigned to $_template->source->content directly.}}
*
* @param Smarty_Template_Source $source source object
* @return string template source
* @throws SmartyException if source cannot be loaded
* @param Smarty_Template_Source $source source object
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public abstract 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_Internal_Template $_template template object
*/
public abstract function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null);
abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null);
/**
* populate Source Object with timestamp and exists from Resource
@ -91,17 +92,21 @@ abstract class Smarty_Resource {
// intentionally left blank
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $is_config flag for config resource
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
{
return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
if ($is_config) {
return get_class($this) . '#' . $smarty->joined_config_dir . '#' . $resource_name;
} else {
return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
}
}
/**
@ -144,13 +149,13 @@ abstract class Smarty_Resource {
$compiled->filepath = $_compile_dir . $_filepath . '.' . $compiled->source->type . $_basename . $_cache . '.php';
}
/**
* Normalize Paths "foo/../bar" to "bar"
* Normalize Paths "foo/../bar" to "bar"
*
* @param string $_path path to normalize
* @param boolean $ds respect windows directory separator
* @return string normalized path
* @param string $_path path to normalize
* @param boolean $ds respect windows directory separator
* @return string normalized path
*/
protected function normalizePath($_path, $ds=true)
{
@ -158,45 +163,45 @@ abstract class Smarty_Resource {
// don't we all just love windows?
$_path = str_replace('\\', '/', $_path);
}
$offset = 0;
// resolve simples
$_path = preg_replace('#(/\./(\./)*)|/{2,}#', '/', $_path);
$_path = preg_replace('#/\./(\./)*#', '/', $_path);
// resolve parents
while (true) {
$_parent = strpos($_path, '/../', $offset);
if (!$_parent) {
break;
} else if ($_path[$_parent - 1] === '.') {
} elseif ($_path[$_parent - 1] === '.') {
$offset = $_parent + 3;
continue;
}
$_pos = strrpos($_path, '/', $_parent - strlen($_path) - 1);
if ($_pos === false) {
// don't we all just love windows?
$_pos = $_parent;
}
$_path = substr_replace($_path, '', $_pos, $_parent + 3 - $_pos);
}
if ($ds && DS != '/') {
// don't we all just love windows?
$_path = str_replace('/', '\\', $_path);
}
return $_path;
}
/**
* build template filepath by traversing the template_dir array
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @return string fully qualified filepath
* @throws SmartyException if default template handler is registered but not callable
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
* @return string fully qualified filepath
* @throws SmartyException if default template handler is registered but not callable
*/
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
{
@ -258,7 +263,7 @@ abstract class Smarty_Resource {
// try string indexes
if (isset($_directories[$match['key']])) {
$_directory = $_directories[$match['key']];
} else if (is_numeric($match['key'])) {
} elseif (is_numeric($match['key'])) {
// try numeric index
$match['key'] = (int) $match['key'];
if (isset($_directories[$match['key']])) {
@ -324,11 +329,13 @@ abstract class Smarty_Resource {
if (is_string($_return)) {
$source->timestamp = @filemtime($_return);
$source->exists = !!$source->timestamp;
return $_return;
} elseif ($_return === true) {
$source->content = $_content;
$source->timestamp = $_timestamp;
$source->exists = true;
return $_filepath;
}
}
@ -340,13 +347,14 @@ abstract class Smarty_Resource {
/**
* test is file exists and save timestamp
*
* @param Smarty_Template_Source $source source object
* @param string $file file name
* @return bool true if file exists
* @param Smarty_Template_Source $source source object
* @param string $file file name
* @return bool true if file exists
*/
protected function fileExists(Smarty_Template_Source $source, $file)
{
$source->timestamp = @filemtime($file);
$source->timestamp = is_file($file) ? @filemtime($file) : false;
return $source->exists = !!$source->timestamp;
}
@ -354,8 +362,8 @@ abstract class Smarty_Resource {
/**
* Determine basename for compiled filename
*
* @param Smarty_Template_Source $source source object
* @return string resource's basename
* @param Smarty_Template_Source $source source object
* @return string resource's basename
*/
protected function getBasename(Smarty_Template_Source $source)
{
@ -365,8 +373,8 @@ abstract class Smarty_Resource {
/**
* Load Resource Handler
*
* @param Smarty $smarty smarty object
* @param string $type name of the resource
* @param Smarty $smarty smarty object
* @param string $type name of the resource
* @return Smarty_Resource Resource Handler
*/
public static function load(Smarty $smarty, $type)
@ -400,6 +408,7 @@ abstract class Smarty_Resource {
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
self::$resources[$type] = new $_resource_class();
}
return $smarty->_resource_handlers[$type] = self::$resources[$type];
}
@ -412,6 +421,7 @@ abstract class Smarty_Resource {
if (class_exists($_resource_class, false)) {
self::$resources[$type] = new $_resource_class();
return $smarty->_resource_handlers[$type] = self::$resources[$type];
} else {
$smarty->registerResource($type, array(
@ -436,6 +446,7 @@ abstract class Smarty_Resource {
if (!isset(self::$resources['stream'])) {
self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
}
return $smarty->_resource_handlers[$type] = self::$resources['stream'];
}
@ -449,10 +460,10 @@ abstract class Smarty_Resource {
* extract resource_type and resource_name from template_resource and config_resource
*
* @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
* @param string $resource_name template_resource or config_resource to parse
* @param string $default_resource the default resource_type defined in $smarty
* @param string &$name the parsed resource name
* @param string &$type the parsed resource type
* @param string $resource_name template_resource or config_resource to parse
* @param string $default_resource the default resource_type defined in $smarty
* @param string &$name the parsed resource name
* @param string &$type the parsed resource type
* @return void
*/
protected static function parseResourceName($resource_name, $default_resource, &$name, &$type)
@ -469,20 +480,19 @@ abstract class Smarty_Resource {
}
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @return string unique resource name
*/
/**
* modify template_resource according to resource handlers specifications
*
* @param string $smarty Smarty instance
* @param string $template_resource template_resource to extracate resource handler and name of
* @param string $smarty Smarty instance
* @param string $template_resource template_resource to extracate resource handler and name of
* @return string unique resource name
*/
public static function getUniqueTemplateName($smarty, $template_resource)
@ -490,6 +500,7 @@ abstract class Smarty_Resource {
self::parseResourceName($template_resource, $smarty->default_resource_type, $name, $type);
// TODO: optimize for Smarty's internal resource types
$resource = Smarty_Resource::load($smarty, $type);
return $resource->buildUniqueResourceName($smarty, $name);
}
@ -498,10 +509,10 @@ abstract class Smarty_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
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
* @return Smarty_Template_Source Source Object
*/
public static function source(Smarty_Internal_Template $_template=null, Smarty $smarty=null, $template_resource=null)
{
@ -530,14 +541,15 @@ abstract class Smarty_Resource {
// runtime cache
self::$sources[$_cache_key] = $source;
return $source;
}
/**
* initialize Config Source Object for given resource
*
* @param Smarty_Internal_Config $_config config object
* @return Smarty_Config_Source Source Object
* @param Smarty_Internal_Config $_config config object
* @return Smarty_Config_Source Source Object
*/
public static function config(Smarty_Internal_Config $_config)
{
@ -555,7 +567,7 @@ abstract class Smarty_Resource {
// load resource handler, identify unique resource name
$resource = Smarty_Resource::load($smarty, $type);
$unique_resource_name = $resource->buildUniqueResourceName($smarty, $name);
$unique_resource_name = $resource->buildUniqueResourceName($smarty, $name, true);
// check runtime cache
$_cache_key = 'config|' . $unique_resource_name;
@ -569,6 +581,7 @@ abstract class Smarty_Resource {
// runtime cache
self::$sources[$_cache_key] = $source;
return $source;
}
@ -584,12 +597,12 @@ abstract class Smarty_Resource {
* @author Rodney Rehm
*
* @property integer $timestamp Source Timestamp
* @property boolean $exists Source Existance
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
* @property string $content Source Content
*/
class Smarty_Template_Source {
class Smarty_Template_Source
{
/**
* Name of the Class to compile this resource's contents with
* @var string
@ -677,12 +690,12 @@ class Smarty_Template_Source {
/**
* create Source Object container
*
* @param Smarty_Resource $handler Resource Handler this source object communicates with
* @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
* @param string $unique_resource unqiue resource name
* @param Smarty_Resource $handler Resource Handler this source object communicates with
* @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
* @param string $unique_resource unqiue resource name
*/
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
{
@ -704,7 +717,7 @@ class Smarty_Template_Source {
/**
* get a Compiled Object of this source
*
* @param Smarty_Internal_Template $_template template objet
* @param Smarty_Internal_Template $_template template objet
* @return Smarty_Template_Compiled compiled object
*/
public function getCompiled(Smarty_Internal_Template $_template)
@ -739,8 +752,8 @@ class Smarty_Template_Source {
/**
* <<magic>> Generic Setter.
*
* @param string $property_name valid: timestamp, exists, content, template
* @param mixed $value new value (is not checked)
* @param string $property_name valid: timestamp, exists, content, template
* @param mixed $value new value (is not checked)
* @throws SmartyException if $property_name is not valid
*/
public function __set($property_name, $value)
@ -763,7 +776,7 @@ class Smarty_Template_Source {
/**
* <<magic>> Generic getter.
*
* @param string $property_name valid: timestamp, exists, content
* @param string $property_name valid: timestamp, exists, content
* @return mixed
* @throws SmartyException if $property_name is not valid
*/
@ -773,6 +786,7 @@ class Smarty_Template_Source {
case 'timestamp':
case 'exists':
$this->handler->populateTimestamp($this);
return $this->$property_name;
case 'content':
@ -796,8 +810,8 @@ class Smarty_Template_Source {
*
* @property string $content compiled content
*/
class Smarty_Template_Compiled {
class Smarty_Template_Compiled
{
/**
* Compiled Filepath
* @var string
@ -811,7 +825,7 @@ class Smarty_Template_Compiled {
public $timestamp = null;
/**
* Compiled Existance
* Compiled Existence
* @var boolean
*/
public $exists = false;
@ -853,5 +867,3 @@ class Smarty_Template_Compiled {
}
}
?>