Files
smarty/libs/sysplugins/smarty_internal_compile_config_load.php

102 lines
3.1 KiB
PHP
Raw Normal View History

<?php
/**
* Smarty Internal Plugin Compile Config Load
* Compiles the {config load} tag
2011-09-16 14:19:56 +00:00
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
2010-08-17 15:39:51 +00:00
/**
* Smarty Internal Plugin Compile Config Load Class
2011-09-16 14:19:56 +00:00
*
* @package Smarty
2011-09-16 14:19:56 +00:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
{
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file', 'section');
2011-09-16 14:19:56 +00:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
2015-11-01 02:58:27 +01:00
public $optional_attributes = array('section', 'scope', 'bubble_up');
/**
* Valid scope names
2016-02-09 01:27:15 +01:00
*
2015-11-01 02:58:27 +01:00
* @var array
*/
2016-02-09 01:27:15 +01:00
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'tpl_root' => true);
/**
* Compiles code for the {config_load} tag
2011-09-16 14:19:56 +00:00
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
2011-09-16 14:19:56 +00:00
$_attr = $this->getAttributes($compiler, $args);
2016-02-09 01:27:15 +01:00
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// save possible attributes
2016-02-09 01:27:15 +01:00
$conf_file = $_attr[ 'file' ];
if (isset($_attr[ 'section' ])) {
$section = $_attr[ 'section' ];
} else {
$section = 'null';
2011-09-16 14:19:56 +00:00
}
2015-11-01 02:58:27 +01:00
$_scope = Smarty::SCOPE_LOCAL;
2016-02-09 01:27:15 +01:00
if (isset($_attr[ 'scope' ])) {
$_attr[ 'scope' ] = trim($_attr[ 'scope' ], "'\"");
if (!isset($this->valid_scopes[ $_attr[ 'scope' ] ])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
true);
2015-11-01 02:58:27 +01:00
}
2016-02-09 01:27:15 +01:00
if ($_attr[ 'scope' ] != 'local') {
if ($_attr[ 'scope' ] == 'parent') {
2015-11-01 02:58:27 +01:00
$_scope = Smarty::SCOPE_PARENT;
2016-02-09 01:27:15 +01:00
} elseif ($_attr[ 'scope' ] == 'root') {
2015-11-01 02:58:27 +01:00
$_scope = Smarty::SCOPE_ROOT;
2016-02-09 01:27:15 +01:00
} elseif ($_attr[ 'scope' ] == 'tpl_root') {
2015-11-01 02:58:27 +01:00
$_scope = Smarty::SCOPE_TPL_ROOT;
}
2016-02-09 01:27:15 +01:00
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
Smarty::SCOPE_BUBBLE_UP;
}
2011-09-16 14:19:56 +00:00
}
2015-11-01 02:58:27 +01:00
// create config object
2015-11-01 02:58:27 +01:00
$_output =
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
return $_output;
2011-09-16 14:19:56 +00:00
}
}