2020-04-13 15:30:52 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Smarty plugin for testing scopes in config vars
|
|
|
|
|
*
|
|
|
|
|
* @package Smarty
|
|
|
|
|
* @subpackage PHPunitPlugin
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-22 21:23:22 +01:00
|
|
|
use Smarty\Template;
|
|
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
/**
|
|
|
|
|
* Smarty {checkconfigvar}
|
|
|
|
|
*
|
|
|
|
|
* @param array $params parameter array
|
|
|
|
|
* @param object $template template object
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function smarty_function_checkconfigvar($params, $template)
|
|
|
|
|
{
|
|
|
|
|
$output = '';
|
|
|
|
|
$types = array('template', 'data', 'smarty');
|
|
|
|
|
if (isset($params['types'])) {
|
|
|
|
|
$types = (array)$params['types'];
|
|
|
|
|
}
|
|
|
|
|
$var = $params['var'];
|
|
|
|
|
$ptr = $template;
|
|
|
|
|
while ($ptr) {
|
2022-12-22 21:23:22 +01:00
|
|
|
if (in_array('template', $types) && $ptr instanceof Template) {
|
2020-04-13 15:30:52 +02:00
|
|
|
$output .= "#{$ptr->source->name}:\${$var} =";
|
|
|
|
|
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
|
|
|
|
|
$ptr = $ptr->parent;
|
|
|
|
|
} elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) {
|
|
|
|
|
$output .= "#data:\${$var} =";
|
|
|
|
|
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
|
|
|
|
|
$ptr = $ptr->parent;
|
|
|
|
|
} else {
|
|
|
|
|
$ptr = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (in_array('smarty', $types)) {
|
|
|
|
|
$output .= "#Smarty:\${$var} =";
|
|
|
|
|
$output .= isset($template->smarty->config_vars[ $var ]) ?
|
|
|
|
|
preg_replace('/\s/', '', var_export($template->smarty->config_vars[ $var ], true)) : 'null';
|
|
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|