2012-07-04 07:23:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile Config Load
|
|
|
|
* Compiles the {config load} tag
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage Compiler
|
2014-09-07 13:38:28 +02:00
|
|
|
* @author Uwe Tews
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile Config Load Class
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
|
|
|
public $required_attributes = array('file');
|
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
public $shorttag_order = array('file', 'section');
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
|
|
|
public $optional_attributes = array('section', 'scope');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles code for the {config_load} tag
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @return string compiled code
|
|
|
|
*/
|
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
2014-09-07 13:38:28 +02:00
|
|
|
static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
|
2012-07-04 07:23:08 +02:00
|
|
|
// check and get attributes
|
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
|
|
|
|
if ($_attr['nocache'] === true) {
|
|
|
|
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
|
|
|
}
|
|
|
|
|
2014-09-07 13:38:28 +02:00
|
|
|
// save possible attributes
|
2012-07-04 07:23:08 +02:00
|
|
|
$conf_file = $_attr['file'];
|
|
|
|
if (isset($_attr['section'])) {
|
|
|
|
$section = $_attr['section'];
|
|
|
|
} else {
|
|
|
|
$section = 'null';
|
|
|
|
}
|
|
|
|
$scope = 'local';
|
|
|
|
// scope setup
|
|
|
|
if (isset($_attr['scope'])) {
|
|
|
|
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
|
|
|
if (isset($_is_legal_scope[$_attr['scope']])) {
|
|
|
|
$scope = $_attr['scope'];
|
2014-09-07 13:38:28 +02:00
|
|
|
} else {
|
2012-07-04 07:23:08 +02:00
|
|
|
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
|
2014-09-07 13:38:28 +02:00
|
|
|
}
|
2012-07-04 07:23:08 +02:00
|
|
|
}
|
|
|
|
// create config object
|
|
|
|
$_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
|
|
|
$_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";
|
2014-09-07 13:38:28 +02:00
|
|
|
|
2012-07-04 07:23:08 +02:00
|
|
|
return $_output;
|
|
|
|
}
|
|
|
|
}
|