smarty_config_source.php 2.9 KB

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