smarty_internal_compile_config_load.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Config Load
  4. * Compiles the {config load} tag
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Config Load Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
  17. {
  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. *
  45. * @return string compiled code
  46. */
  47. public function compile($args, $compiler)
  48. {
  49. static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
  50. // check and get attributes
  51. $_attr = $this->getAttributes($compiler, $args);
  52. if ($_attr['nocache'] === true) {
  53. $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
  54. }
  55. // save possible attributes
  56. $conf_file = $_attr['file'];
  57. if (isset($_attr['section'])) {
  58. $section = $_attr['section'];
  59. } else {
  60. $section = 'null';
  61. }
  62. $scope = 'local';
  63. // scope setup
  64. if (isset($_attr['scope'])) {
  65. $_attr['scope'] = trim($_attr['scope'], "'\"");
  66. if (isset($_is_legal_scope[$_attr['scope']])) {
  67. $scope = $_attr['scope'];
  68. } else {
  69. $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
  70. }
  71. }
  72. // create config object
  73. $_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
  74. $_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";
  75. return $_output;
  76. }
  77. }