smarty_config_source.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Smarty Internal Plugin
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. */
  8. /**
  9. * Smarty Resource Data Object
  10. * Meta Data Container for Config Files
  11. *
  12. * @package Smarty
  13. * @subpackage TemplateResources
  14. * @author Rodney Rehm
  15. * @property string $content
  16. * @property int $timestamp
  17. * @property bool $exists
  18. */
  19. class Smarty_Config_Source extends Smarty_Template_Source
  20. {
  21. /**
  22. * create Config Object container
  23. *
  24. * @param Smarty_Resource $handler Resource Handler this source object communicates with
  25. * @param Smarty $smarty Smarty instance this source object belongs to
  26. * @param string $resource full config_resource
  27. * @param string $type type of resource
  28. * @param string $name resource name
  29. * @param string $unique_resource unqiue resource name
  30. */
  31. public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
  32. {
  33. $this->handler = $handler; // Note: prone to circular references
  34. // Note: these may be ->config_compiler_class etc in the future
  35. //$this->config_compiler_class = $handler->config_compiler_class;
  36. //$this->config_lexer_class = $handler->config_lexer_class;
  37. //$this->config_parser_class = $handler->config_parser_class;
  38. $this->smarty = $smarty;
  39. $this->resource = $resource;
  40. $this->type = $type;
  41. $this->name = $name;
  42. $this->unique_resource = $unique_resource;
  43. }
  44. /**
  45. * <<magic>> Generic setter.
  46. *
  47. * @param string $property_name valid: content, timestamp, exists
  48. * @param mixed $value newly assigned value (not check for correct type)
  49. *
  50. * @throws SmartyException when the given property name is not valid
  51. */
  52. public function __set($property_name, $value)
  53. {
  54. switch ($property_name) {
  55. case 'content':
  56. case 'timestamp':
  57. case 'exists':
  58. $this->$property_name = $value;
  59. break;
  60. default:
  61. throw new SmartyException("invalid config property '$property_name'.");
  62. }
  63. }
  64. /**
  65. * <<magic>> Generic getter.
  66. *
  67. * @param string $property_name valid: content, timestamp, exists
  68. *
  69. * @return mixed|void
  70. * @throws SmartyException when the given property name is not valid
  71. */
  72. public function __get($property_name)
  73. {
  74. switch ($property_name) {
  75. case 'timestamp':
  76. case 'exists':
  77. $this->handler->populateTimestamp($this);
  78. return $this->$property_name;
  79. case 'content':
  80. return $this->content = $this->handler->getContent($this);
  81. default:
  82. throw new SmartyException("config property '$property_name' does not exist.");
  83. }
  84. }
  85. }