smarty_template_config.php (4087B)
1 <?php 2 /** 3 * Smarty Config Source Plugin 4 * 5 * @package Smarty 6 * @subpackage TemplateResources 7 * @author Uwe Tews 8 */ 9 10 /** 11 * Smarty Connfig Resource Data Object 12 * Meta Data Container for Template Files 13 * 14 * @package Smarty 15 * @subpackage TemplateResources 16 * @author Uwe Tews 17 * @property integer $timestamp Source Timestamp 18 * @property boolean $exists Source Existence 19 * @property boolean $template Extended Template reference 20 * @property string $content Source Content 21 */ 22 class Smarty_Template_Config extends Smarty_Template_Source 23 { 24 /** 25 * Name of the Class to compile this resource's contents with 26 * 27 * @var string 28 */ 29 public $compiler_class = 'Smarty_Internal_Config_File_Compiler'; 30 31 /** 32 * Name of the Class to tokenize this resource's contents with 33 * 34 * @var string 35 */ 36 public $template_lexer_class = 'Smarty_Internal_Configfilelexer'; 37 38 /** 39 * Name of the Class to parse this resource's contents with 40 * 41 * @var string 42 */ 43 public $template_parser_class = 'Smarty_Internal_Configfileparser'; 44 45 /** 46 * array of section names, single section or null 47 * 48 * @var null|string|array 49 */ 50 public $config_sections = null; 51 52 /** 53 * scope into which the config variables shall be loaded 54 * 55 * @var string 56 */ 57 public $scope = 'local'; 58 59 /** 60 * Flag that source is a config file 61 * 62 * @var bool 63 */ 64 public $isConfig = true; 65 66 /** 67 * create Source Object container 68 * 69 * @param Smarty_Resource $handler Resource Handler this source object communicates with 70 * @param Smarty $smarty Smarty instance this source object belongs to 71 * @param string $resource full template_resource 72 * @param string $type type of resource 73 * @param string $name resource name 74 */ 75 public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) 76 { 77 $this->handler = clone $handler; // Note: prone to circular references 78 $this->resource = $resource; 79 $this->type = $type; 80 $this->name = $name; 81 $this->smarty = $smarty; 82 } 83 84 /** 85 * initialize Source Object for given resource 86 * Either [$_template] or [$smarty, $template_resource] must be specified 87 * 88 * @param Smarty_Internal_Template $_template template object 89 * @param Smarty $smarty smarty object 90 * @param string $template_resource resource identifier 91 * 92 * @return Smarty_Template_Source Source Object 93 * @throws SmartyException 94 */ 95 public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) 96 { 97 static $_incompatible_resources = array('extends' => true, 'php' => true); 98 $smarty = $_template->smarty; 99 $template_resource = $_template->template_resource; 100 if (empty($template_resource)) { 101 throw new SmartyException('Missing config name'); 102 } 103 // parse resource_name, load resource handler 104 list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type); 105 // make sure configs are not loaded via anything smarty can't handle 106 if (isset($_incompatible_resources[$type])) { 107 throw new SmartyException ("Unable to use resource '{$type}' for config"); 108 } 109 $resource = Smarty_Resource::load($smarty, $type); 110 $source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name); 111 $resource->populate($source, $_template); 112 if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_config_handler_func)) { 113 Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resource); 114 } 115 $source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true); 116 return $source; 117 } 118 }