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 /** |
|
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 /** |
|
41 * Compiles code for the {config_load} tag |
|
42 * |
|
43 * @param array $args array with attributes from parser |
|
44 * @param object $compiler compiler object |
|
45 * |
|
46 * @return string compiled code |
|
47 */ |
|
48 public function compile($args, $compiler) { |
|
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 |
|
53 if ($_attr['nocache'] === true) { |
|
54 $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |
|
55 } |
|
56 |
|
57 // save possible attributes |
|
58 $conf_file = $_attr['file']; |
|
59 if (isset($_attr['section'])) { |
|
60 $section = $_attr['section']; |
|
61 } else { |
|
62 $section = 'null'; |
|
63 } |
|
64 $scope = 'local'; |
|
65 // scope setup |
|
66 if (isset($_attr['scope'])) { |
|
67 $_attr['scope'] = trim($_attr['scope'], "'\""); |
|
68 if (isset($_is_legal_scope[$_attr['scope']])) { |
|
69 $scope = $_attr['scope']; |
|
70 } else { |
|
71 $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); |
|
72 } |
|
73 } |
|
74 // create config object |
|
75 $_output = "<?php Smarty_Internal_Extension_Config::configLoad(\$_smarty_tpl, $conf_file, $section, '$scope');?>"; |
|
76 |
|
77 return $_output; |
|
78 } |
|
79 } |
|