- update for PHP 5.4 compatibility

- reformat source to PSR-2 standard
This commit is contained in:
Uwe.Tews@googlemail.com
2013-07-14 22:15:45 +00:00
parent f99e6a83ce
commit 00ccae8857
126 changed files with 5232 additions and 5186 deletions

View File

@@ -15,22 +15,23 @@
* @package Smarty
* @subpackage TemplateResources
*/
abstract class Smarty_Resource {
abstract class Smarty_Resource
{
/**
* cache for Smarty_Template_Source instances
* @var array
*/
public static $sources = array();
static $sources = array();
/**
* cache for Smarty_Template_Compiled instances
* @var array
*/
public static $compileds = array();
static $compileds = array();
/**
* cache for Smarty_Resource instances
* @var array
*/
public static $resources = array();
static $resources = array();
/**
* resource types provided by the core
* @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,12 +92,11 @@ 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
* @return string unique resource name
*/
protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
@@ -144,13 +144,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,9 +158,9 @@ abstract class Smarty_Resource {
// don't we all just love windows?
$_path = str_replace('\\', '/', $_path);
}
$offset = 0;
// resolve simples
$_path = preg_replace('#/\./(\./)*#', '/', $_path);
// resolve parents
@@ -168,35 +168,35 @@ abstract class Smarty_Resource {
$_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 +258,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 +324,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 +342,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);
return $source->exists = !!$source->timestamp;
}
@@ -354,8 +357,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,11 +368,11 @@ 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)
static function load(Smarty $smarty, $type)
{
// try smarty's cache
if (isset($smarty->_resource_handlers[$type])) {
@@ -400,6 +403,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 +416,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 +441,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 +455,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,27 +475,27 @@ 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)
static function getUniqueTemplateName($smarty, $template_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,12 +504,12 @@ 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)
static function source(Smarty_Internal_Template $_template=null, Smarty $smarty=null, $template_resource=null)
{
if ($_template) {
$smarty = $_template->smarty;
@@ -530,16 +536,17 @@ 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)
static function config(Smarty_Internal_Config $_config)
{
static $_incompatible_resources = array('eval' => true, 'string' => true, 'extends' => true, 'php' => true);
$config_resource = $_config->config_resource;
@@ -569,6 +576,7 @@ abstract class Smarty_Resource {
// runtime cache
self::$sources[$_cache_key] = $source;
return $source;
}
@@ -588,8 +596,8 @@ abstract class Smarty_Resource {
* @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 +685,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 +712,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 +747,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 +771,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 +781,7 @@ class Smarty_Template_Source {
case 'timestamp':
case 'exists':
$this->handler->populateTimestamp($this);
return $this->$property_name;
case 'content':
@@ -796,8 +805,8 @@ class Smarty_Template_Source {
*
* @property string $content compiled content
*/
class Smarty_Template_Compiled {
class Smarty_Template_Compiled
{
/**
* Compiled Filepath
* @var string
@@ -853,5 +862,3 @@ class Smarty_Template_Compiled {
}
}
?>