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_internal_compile_config_load.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * Attribute definition: Overwrites base class.
  41. *
  42. * @var array
  43. * @see Smarty_Internal_CompileBase
  44. */
  45. public $option_flags = array('nocache', 'noscope');
  46. /**
  47. * Valid scope names
  48. *
  49. * @var array
  50. */
  51. public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
  52. 'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
  53. 'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY);
  54. /**
  55. * Compiles code for the {config_load} tag
  56. *
  57. * @param array $args array with attributes from parser
  58. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  59. *
  60. * @return string compiled code
  61. * @throws \SmartyCompilerException
  62. */
  63. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
  64. {
  65. // check and get attributes
  66. $_attr = $this->getAttributes($compiler, $args);
  67. if ($_attr[ 'nocache' ] === true) {
  68. $compiler->trigger_template_error('nocache option not allowed', null, true);
  69. }
  70. // save possible attributes
  71. $conf_file = $_attr[ 'file' ];
  72. if (isset($_attr[ 'section' ])) {
  73. $section = $_attr[ 'section' ];
  74. } else {
  75. $section = 'null';
  76. }
  77. // scope setup
  78. if ($_attr[ 'noscope' ]) {
  79. $_scope = - 1;
  80. } else {
  81. $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
  82. }
  83. // create config object
  84. $_output =
  85. "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
  86. return $_output;
  87. }
  88. }