/** * initialize Source Object for given 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_Config Source Object * @throws SmartyException */ public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) { static $_incompatible_resources = array('extends' => true, 'php' => true); $template_resource = $_template->template_resource; if (empty($template_resource)) { throw new SmartyException('Missing config name'); } // parse resource_name, load resource handler list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type); // make sure configs are not loaded via anything smarty can't handle if (isset($_incompatible_resources[$type])) { throw new SmartyException("Unable to use resource '{$type}' for config"); } $source = new Smarty_Template_Config($_template->smarty, $template_resource, $type, $name); $source->handler->populate($source, $_template); if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); } return $source; }
/** * initialize Source Object for given 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 * @throws SmartyException */ public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) { if ($_template) { $smarty = $_template->smarty; $template_resource = $_template->template_resource; } if (empty($template_resource)) { throw new SmartyException('Source: Missing name'); } // parse resource_name, load resource handler, identify unique resource name if (preg_match('/^([A-Za-z0-9_\\-]{2,})[:]([\\s\\S]*)$/', $template_resource, $match)) { $type = $match[1]; $name = $match[2]; } else { // no resource given, use default // or single character before the colon is not a resource type, but part of the filepath $type = $smarty->default_resource_type; $name = $template_resource; } // create new source object $source = new Smarty_Template_Source($smarty, $template_resource, $type, $name); $source->handler->populate($source, $_template); if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); $source->handler->populate($source, $_template); } return $source; }
/** * initialize Source Object for given 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 * @throws SmartyException */ public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) { if ($_template) { $smarty = $_template->smarty; $template_resource = $_template->template_resource; } if (empty($template_resource)) { throw new SmartyException('Missing template name'); } // parse resource_name, load resource handler, identify unique resource name list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_resource_type); $handler = Smarty_Resource::load($smarty, $type); // if resource is not recompiling and resource name is not dotted we can check the source cache if ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON && !$handler->recompiled && !(isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'))) { $unique_resource = $handler->buildUniqueResourceName($smarty, $name); if (isset($smarty->_cache['source_objects'][$unique_resource])) { return $smarty->_cache['source_objects'][$unique_resource]; } } else { $unique_resource = null; } // create new source object $source = new Smarty_Template_Source($handler, $smarty, $template_resource, $type, $name); $handler->populate($source, $_template); if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); } // on recompiling resources we are done if ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON && !$handler->recompiled) { // may by we have already $unique_resource $is_relative = false; if (!isset($unique_resource)) { $is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') && ($type == 'file' || isset($_template->parent->source) && $_template->parent->source->type == 'extends'); $unique_resource = $handler->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name); } $source->unique_resource = $unique_resource; // save in runtime cache if not relative if (!$is_relative) { $smarty->_cache['source_objects'][$unique_resource] = $source; } } return $source; }