Files
smarty/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php

60 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/**
* Smarty plugin for testing scopes
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
2022-12-22 21:50:01 +01:00
use Smarty\DataObject;
2022-12-22 21:23:22 +01:00
use Smarty\Template;
/**
* Smarty {checkvar}
*
* @param array $params parameter array
* @param object $template template object
*
* @return string
*/
function smarty_function_checkvar($params, $template)
{
$output = '';
$types = array('template', 'data', 'smarty', 'global');
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) {
$output .= "#{$ptr->source->name}:\${$var} =";
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
$i = 0;
2022-11-28 12:30:07 +01:00
while (isset($ptr->_var_stack[ $i ])) {
$output .= "#{$ptr->_var_stack[ $i ]['name']} = ";
$output .= isset($ptr->_var_stack[ $i ][ 'tpl' ][$var]) ? preg_replace('/\s/', '', var_export($ptr->_var_stack[ $i ][ 'tpl' ][$var]->value, true)) : '>unassigned<';
$i ++;
}
$ptr = $ptr->parent;
2022-12-22 21:50:01 +01:00
} elseif (in_array('data', $types) && $ptr instanceof DataObject) {
$output .= "#data:\${$var} =";
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
$ptr = $ptr->parent;
} else {
$ptr = null;
}
}
if (in_array('smarty', $types)) {
$output .= "#Smarty:\${$var} =";
$output .= isset($template->smarty->tpl_vars[ $var ]) ?
preg_replace('/\s/', '', var_export($template->smarty->tpl_vars[ $var ]->value, true)) : '>unassigned<';
}
if (in_array('global', $types)) {
$output .= "#global:\${$var} =";
2022-11-30 00:25:27 +01:00
$output .= isset(\Smarty\Smarty::$global_tpl_vars[ $var ]) ?
preg_replace('/\s/', '', var_export(\Smarty\Smarty::$global_tpl_vars[ $var ]->value, true)) : '>unassigned<';
}
return $output;
}