]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/plugins/shared.literal_compiler_param.php
Merge branch 'develop' of github.com:annando/friendica into 1409-shadow-items
[friendica.git] / library / Smarty / libs / plugins / shared.literal_compiler_param.php
1 <?php
2 /**
3  * Smarty plugin
4  *
5  * @package    Smarty
6  * @subpackage PluginsShared
7  */
8
9 /**
10  * evaluate compiler parameter
11  *
12  * @param array   $params  parameter array as given to the compiler function
13  * @param integer $index   array index of the parameter to convert
14  * @param mixed   $default value to be returned if the parameter is not present
15  *
16  * @return mixed evaluated value of parameter or $default
17  * @throws SmartyException if parameter is not a literal (but an expression, variable, …)
18  * @author Rodney Rehm
19  */
20 function smarty_literal_compiler_param($params, $index, $default = null)
21 {
22     // not set, go default
23     if (!isset($params[$index])) {
24         return $default;
25     }
26     // test if param is a literal
27     if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[$index])) {
28         throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time');
29     }
30
31     $t = null;
32     eval("\$t = " . $params[$index] . ";");
33
34     return $t;
35 }