fusionpbx/resources/templates/engine/smarty/plugins/shared.literal_compiler_par...

36 lines
1.0 KiB
PHP
Raw Normal View History

2013-11-09 21:02:56 +01:00
<?php
/**
* Smarty plugin
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage PluginsShared
*/
/**
* evaluate compiler parameter
*
* @param array $params parameter array as given to the compiler function
* @param integer $index array index of the parameter to convert
* @param mixed $default value to be returned if the parameter is not present
2018-11-07 08:18:14 +01:00
*
2013-11-09 21:02:56 +01:00
* @return mixed evaluated value of parameter or $default
* @throws SmartyException if parameter is not a literal (but an expression, variable, )
* @author Rodney Rehm
*/
2018-11-07 08:18:14 +01:00
function smarty_literal_compiler_param($params, $index, $default = null)
2013-11-09 21:02:56 +01:00
{
// not set, go default
2018-11-07 08:18:14 +01:00
if (!isset($params[ $index ])) {
2013-11-09 21:02:56 +01:00
return $default;
}
// test if param is a literal
2018-11-07 08:18:14 +01:00
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new SmartyException(
'$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
2013-11-09 21:02:56 +01:00
}
$t = null;
2018-11-07 08:18:14 +01:00
eval("\$t = " . $params[ $index ] . ";");
2013-11-09 21:02:56 +01:00
return $t;
}