mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
Small optimization
This commit is contained in:
@@ -37,7 +37,9 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
}
|
||||
preg_match('#^((?P<absolute>[\/]|[a-zA-Z]:[\/])|(\[(?P<index>[^\]]+)\])|((?P<rel1>\.[\/])?(?P<rel2>(\.\.[\/])*))|(?P<skip>[\/]))?(?P<file>.+)$#', $file, $fileMatch);
|
||||
// save basename
|
||||
$source->basename = $fileMatch['file'];
|
||||
if (!empty($fileMatch['absolute'])) {
|
||||
return is_file($file) ? $file : false;
|
||||
}
|
||||
// go relative to a given template?
|
||||
if ($_template && $_template->parent instanceof Smarty_Internal_Template && (!empty($fileMatch['rel1']) || !empty($fileMatch['rel2']))) {
|
||||
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) {
|
||||
@@ -92,7 +94,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
}
|
||||
|
||||
// relative file name?
|
||||
if (empty($fileMatch['absolute'])) {
|
||||
foreach ($_directories as $_directory) {
|
||||
if (empty($fileMatch['rel2'])) {
|
||||
$_filepath = $_directory . $fileMatch['file'];
|
||||
@@ -124,12 +125,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// try absolute filepath
|
||||
if (is_file($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
// Could be relative to cwd
|
||||
$path = str_replace('\\', '/', getcwd());
|
||||
if (empty($fileMatch['rel2'])) {
|
||||
@@ -159,9 +154,8 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
|
||||
*
|
||||
*@param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
@@ -223,6 +217,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return $source->basename;
|
||||
return basename($source->filepath);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user