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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Smarty Config Source Plugin
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. */
  9. /**
  10. * Smarty Config 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 int
  30. */
  31. public $scope = 0;
  32. /**
  33. * Flag that source is a config file
  34. *
  35. * @var bool
  36. */
  37. public $isConfig = true;
  38. /**
  39. * Name of the Class to compile this resource's contents with
  40. *
  41. * @var string
  42. */
  43. public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
  44. /**
  45. * Name of the Class to tokenize this resource's contents with
  46. *
  47. * @var string
  48. */
  49. public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
  50. /**
  51. * Name of the Class to parse this resource's contents with
  52. *
  53. * @var string
  54. */
  55. public $template_parser_class = 'Smarty_Internal_Configfileparser';
  56. /**
  57. * initialize Source Object for given resource
  58. * Either [$_template] or [$smarty, $template_resource] must be specified
  59. *
  60. * @param Smarty_Internal_Template $_template template object
  61. * @param Smarty $smarty smarty object
  62. * @param string $template_resource resource identifier
  63. *
  64. * @return Smarty_Template_Config Source Object
  65. * @throws SmartyException
  66. */
  67. public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
  68. $template_resource = null)
  69. {
  70. static $_incompatible_resources = array('extends' => true, 'php' => true);
  71. if ($_template) {
  72. $smarty = $_template->smarty;
  73. $template_resource = $_template->template_resource;
  74. }
  75. if (empty($template_resource)) {
  76. throw new SmartyException('Source: Missing name');
  77. }
  78. // parse resource_name, load resource handler
  79. list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
  80. // make sure configs are not loaded via anything smarty can't handle
  81. if (isset($_incompatible_resources[ $type ])) {
  82. throw new SmartyException ("Unable to use resource '{$type}' for config");
  83. }
  84. $source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
  85. $source->handler->populate($source, $_template);
  86. if (!$source->exists && isset($smarty->default_config_handler_func)) {
  87. Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
  88. $source->handler->populate($source, $_template);
  89. }
  90. return $source;
  91. }
  92. }