You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_template_config.php 3.5KB

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