summaryrefslogtreecommitdiff
path: root/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php')
-rw-r--r--tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php
new file mode 100644
index 00000000..94fcc2c9
--- /dev/null
+++ b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Smarty plugin for testing scopes in config vars
+ *
+
+
+ */
+
+use Smarty\Template;
+
+/**
+ * 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', 'global');
+ if (isset($params['types'])) {
+ $types = (array)$params['types'];
+ }
+ $var = $params['var'];
+ $ptr = $template;
+ while ($ptr) {
+ if (in_array('template', $types) && $ptr instanceof Template) {
+ $output .= "#{$ptr->getSource()->name}:\${$var} =";
+ $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
+ $ptr = $ptr->parent;
+ } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) {
+ $output .= "#data:\${$var} =";
+ $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
+ $ptr = $ptr->parent;
+ } else {
+ $ptr = null;
+ }
+ }
+ if (in_array('global', $types)) {
+ $output .= "#global:\${$var} =";
+ $output .= $template->getSmarty()->hasConfigVariable($var) ?
+ preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null';
+ }
+ return $output;
+}