smarty_internal_compile_config_load.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Config Load
  4. *
  5. * Compiles the {config load} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Config Load Class
  13. *
  14. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $required_attributes = array('file');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $shorttag_order = array('file','section');
  32. /**
  33. * Attribute definition: Overwrites base class.
  34. *
  35. * @var array
  36. * @see Smarty_Internal_CompileBase
  37. */
  38. public $optional_attributes = array('section', 'scope');
  39. /**
  40. * Compiles code for the {config_load} tag
  41. *
  42. * @param array $args array with attributes from parser
  43. * @param object $compiler compiler object
  44. * @return string compiled code
  45. */
  46. public function compile($args, $compiler)
  47. {
  48. static $_is_legal_scope = array('local' => true,'parent' => true,'root' => true,'global' => true);
  49. // check and get attributes
  50. $_attr = $this->getAttributes($compiler, $args);
  51. if ($_attr['nocache'] === true) {
  52. $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
  53. }
  54. // save posible attributes
  55. $conf_file = $_attr['file'];
  56. if (isset($_attr['section'])) {
  57. $section = $_attr['section'];
  58. } else {
  59. $section = 'null';
  60. }
  61. $scope = 'local';
  62. // scope setup
  63. if (isset($_attr['scope'])) {
  64. $_attr['scope'] = trim($_attr['scope'], "'\"");
  65. if (isset($_is_legal_scope[$_attr['scope']])) {
  66. $scope = $_attr['scope'];
  67. } else {
  68. $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
  69. }
  70. }
  71. // create config object
  72. $_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
  73. $_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";
  74. return $_output;
  75. }
  76. }
  77. ?>