summaryrefslogtreecommitdiff
path: root/lib/smarty3/sysplugins/smarty_resource.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_resource.php')
-rw-r--r--lib/smarty3/sysplugins/smarty_resource.php230
1 files changed, 119 insertions, 111 deletions
diff --git a/lib/smarty3/sysplugins/smarty_resource.php b/lib/smarty3/sysplugins/smarty_resource.php
index 0c9ba75..aae7e42 100644
--- a/lib/smarty3/sysplugins/smarty_resource.php
+++ b/lib/smarty3/sysplugins/smarty_resource.php
@@ -21,6 +21,20 @@
abstract class Smarty_Resource
{
/**
+ * resource types provided by the core
+ *
+ * @var array
+ */
+ public static $sysplugins = array(
+ 'file' => 'smarty_internal_resource_file.php',
+ 'string' => 'smarty_internal_resource_string.php',
+ 'extends' => 'smarty_internal_resource_extends.php',
+ 'stream' => 'smarty_internal_resource_stream.php',
+ 'eval' => 'smarty_internal_resource_eval.php',
+ 'php' => 'smarty_internal_resource_php.php'
+ );
+
+ /**
* Source is bypassing compiler
*
* @var boolean
@@ -35,18 +49,6 @@ abstract class Smarty_Resource
public $recompiled = false;
/**
- * resource types provided by the core
- *
- * @var array
- */
- public static $sysplugins = array('file' => 'smarty_internal_resource_file.php',
- 'string' => 'smarty_internal_resource_string.php',
- 'extends' => 'smarty_internal_resource_extends.php',
- 'stream' => 'smarty_internal_resource_stream.php',
- 'eval' => 'smarty_internal_resource_eval.php',
- 'php' => 'smarty_internal_resource_php.php');
-
- /**
* Flag if resource does implement populateCompiledFilepath() method
*
* @var bool
@@ -54,74 +56,10 @@ abstract class Smarty_Resource
public $hasCompiledHandler = false;
/**
- * Load template's source into current template 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);
-
- /**
- * populate Source Object with meta data from Resource
- *
- * @param Smarty_Template_Source $source source object
- * @param Smarty_Internal_Template $_template template object
- */
- abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
-
- /**
- * populate Source Object with timestamp and exists from Resource
- *
- * @param Smarty_Template_Source $source source object
- */
- public function populateTimestamp(Smarty_Template_Source $source)
- {
- // 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 boolean $isConfig flag for config resource
- *
- * @return string unique resource name
- */
- public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
- {
- if ($isConfig) {
- if (!isset($smarty->_joined_config_dir)) {
- $smarty->getTemplateDir(null, true);
- }
- return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
- } else {
- if (!isset($smarty->_joined_template_dir)) {
- $smarty->getTemplateDir();
- }
- return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
- }
- }
-
- /**
- * Determine basename for compiled filename
- *
- * @param Smarty_Template_Source $source source object
- *
- * @return string resource's basename
- */
- public function getBasename(Smarty_Template_Source $source)
- {
- return basename(preg_replace('![^\w]+!', '_', $source->name));
- }
-
- /**
* 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
*
* @throws SmartyException
* @return Smarty_Resource Resource Handler
@@ -132,34 +70,34 @@ abstract class Smarty_Resource
if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) {
return $smarty->_cache[ 'resource_handlers' ][ $type ];
}
-
// try registered resource
if (isset($smarty->registered_resources[ $type ])) {
return $smarty->_cache[ 'resource_handlers' ][ $type ] =
$smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
$smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
}
-
// try sysplugins dir
if (isset(self::$sysplugins[ $type ])) {
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
}
-
// try plugins dir
$_resource_class = 'Smarty_Resource_' . ucfirst($type);
if ($smarty->loadPlugin($_resource_class)) {
if (class_exists($_resource_class, false)) {
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
} else {
- $smarty->registerResource($type,
- array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
- "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
+ $smarty->registerResource(
+ $type,
+ array(
+ "smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
+ "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"
+ )
+ );
// give it another try, now that the resource is registered properly
return self::load($smarty, $type);
}
}
-
// try streams
$_known_stream = stream_get_wrappers();
if (in_array($type, $_known_stream)) {
@@ -169,19 +107,18 @@ abstract class Smarty_Resource
}
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream();
}
-
// TODO: try default_(template|config)_handler
-
// give up
throw new SmartyException("Unknown resource type '{$type}'");
}
/**
* 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 $resource_name template_resource or config_resource to parse
+ * @param string $default_resource the default resource_type defined in $smarty
*
* @return array with parsed resource name and type
*/
@@ -202,53 +139,124 @@ abstract class Smarty_Resource
/**
* modify template_resource according to resource handlers specifications
*
- * @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
- * @param string $template_resource template_resource to extract resource handler and name of
+ * @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
+ * @param string $template_resource template_resource to extract resource handler and
+ * name of
*
* @return string unique resource name
+ * @throws \SmartyException
*/
public static function getUniqueTemplateName($obj, $template_resource)
{
- $smarty = $obj->_objType == 2 ? $obj->smarty : $obj;
+ $smarty = $obj->_getSmartyObj();
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
// TODO: optimize for Smarty's internal resource types
$resource = Smarty_Resource::load($smarty, $type);
// go relative to a given template?
- $_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/');
- if ($obj->_objType == 2 && $_file_is_dotted &&
- ($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
+ $_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/');
+ if ($obj->_isTplObj() && $_file_is_dotted
+ && ($obj->source->type === 'file' || $obj->parent->source->type === 'extends')
) {
- $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name);
+ $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DIRECTORY_SEPARATOR . $name);
}
return $resource->buildUniqueResourceName($smarty, $name);
}
+ /**
+ * initialize Source Object for given resource
+ * 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 $smarty smarty object
+ * @param string $template_resource resource identifier
+ *
+ * @return \Smarty_Template_Source Source Object
+ * @throws \SmartyException
+ */
+ public static function source(
+ Smarty_Internal_Template $_template = null,
+ Smarty $smarty = null,
+ $template_resource = null
+ ) {
+ return Smarty_Template_Source::load($_template, $smarty, $template_resource);
+ }
+
+ /**
+ * Load template's source into current template 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);
+
+ /**
+ * populate Source Object with meta data from Resource
+ *
+ * @param Smarty_Template_Source $source source object
+ * @param Smarty_Internal_Template $_template template object
+ */
+ abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
+
+ /**
+ * populate Source Object with timestamp and exists from Resource
+ *
+ * @param Smarty_Template_Source $source source object
+ */
+ public function populateTimestamp(Smarty_Template_Source $source)
+ {
+ // 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 boolean $isConfig flag for config resource
+ *
+ * @return string unique resource name
+ */
+ public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
+ {
+ if ($isConfig) {
+ if (!isset($smarty->_joined_config_dir)) {
+ $smarty->getTemplateDir(null, true);
+ }
+ return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
+ } else {
+ if (!isset($smarty->_joined_template_dir)) {
+ $smarty->getTemplateDir();
+ }
+ return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
+ }
+ }
+
/*
* Check if resource must check time stamps when when loading complied or cached templates.
* Resources like 'extends' which use source components my disable timestamp checks on own resource.
*
* @return bool
*/
- public function checkTimestamps()
+ /**
+ * Determine basename for compiled filename
+ *
+ * @param Smarty_Template_Source $source source object
+ *
+ * @return string resource's basename
+ */
+ public function getBasename(Smarty_Template_Source $source)
{
- return true;
+ return basename(preg_replace('![^\w]+!', '_', $source->name));
}
/**
- * initialize Source Object for given resource
- * 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 $smarty smarty object
- * @param string $template_resource resource identifier
- *
- * @return Smarty_Template_Source Source Object
+ * @return bool
*/
- public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
- $template_resource = null)
+ public function checkTimestamps()
{
- return Smarty_Template_Source::load($_template, $smarty, $template_resource);
+ return true;
}
}
-