smarty_internal_compile_config_load.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {config_load} tag
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->required_attributes = array('file');
  26. $this->optional_attributes = array('section', 'scope');
  27. // check and get attributes
  28. $_attr = $this->_get_attributes($args);
  29. // save posible attributes
  30. $conf_file = $_attr['file'];
  31. if (isset($_attr['section'])) {
  32. $section = $_attr['section'];
  33. } else {
  34. $section = 'null';
  35. }
  36. $scope = '$_smarty_tpl->smarty';
  37. if (isset($_attr['scope'])) {
  38. if ($_attr['scope'] == '\'local\'') {
  39. $scope = '$_smarty_tpl';
  40. } elseif ($_attr['scope'] == '\'parent\'') {
  41. $scope = '$_smarty_tpl->parent';
  42. }
  43. }
  44. // create config object
  45. $_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
  46. $_output .= "\$_config->loadConfigVars($section, $scope); ?>";
  47. return $_output;
  48. }
  49. }
  50. ?>