aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template/twig/extension.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/template/twig/extension.php')
-rw-r--r--phpBB/phpbb/template/twig/extension.php30
1 files changed, 23 insertions, 7 deletions
diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php
index f6f8e03ca2..1131a7f3aa 100644
--- a/phpBB/phpbb/template/twig/extension.php
+++ b/phpBB/phpbb/template/twig/extension.php
@@ -18,6 +18,9 @@ class extension extends \Twig_Extension
/** @var \phpbb\template\context */
protected $context;
+ /** @var \phpbb\template\twig\environment */
+ protected $environment;
+
/** @var \phpbb\language\language */
protected $language;
@@ -25,12 +28,13 @@ class extension extends \Twig_Extension
* Constructor
*
* @param \phpbb\template\context $context
+ * @param \phpbb\template\twig\environment $environment
* @param \phpbb\language\language $language
- * @return \phpbb\template\twig\extension
*/
- public function __construct(\phpbb\template\context $context, $language)
+ public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language)
{
$this->context = $context;
+ $this->environment = $environment;
$this->language = $language;
}
@@ -56,9 +60,9 @@ class extension extends \Twig_Extension
new \phpbb\template\twig\tokenparser\includeparser,
new \phpbb\template\twig\tokenparser\includejs,
new \phpbb\template\twig\tokenparser\includecss,
- new \phpbb\template\twig\tokenparser\event,
- new \phpbb\template\twig\tokenparser\includephp,
- new \phpbb\template\twig\tokenparser\php,
+ new \phpbb\template\twig\tokenparser\event($this->environment),
+ new \phpbb\template\twig\tokenparser\includephp($this->environment),
+ new \phpbb\template\twig\tokenparser\php($this->environment),
);
}
@@ -85,6 +89,8 @@ class extension extends \Twig_Extension
{
return array(
new \Twig_SimpleFunction('lang', array($this, 'lang')),
+ new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')),
+ new \Twig_SimpleFunction('get_class', 'get_class'),
);
}
@@ -136,7 +142,7 @@ class extension extends \Twig_Extension
*
* @return mixed The sliced variable
*/
- function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
+ public function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
{
// We do almost the same thing as Twig's slice (array_slice), except when $end is positive
if ($end >= 1)
@@ -165,7 +171,7 @@ class extension extends \Twig_Extension
*
* @return string
*/
- function lang()
+ public function lang()
{
$args = func_get_args();
$key = $args[0];
@@ -182,4 +188,14 @@ class extension extends \Twig_Extension
return call_user_func_array(array($this->language, 'lang'), $args);
}
+
+ /**
+ * Check if a language variable exists
+ *
+ * @return bool
+ */
+ public function lang_defined($key)
+ {
+ return call_user_func_array([$this->language, 'is_set'], [$key]);
+ }
}