aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template/twig
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/template/twig')
-rw-r--r--phpBB/phpbb/template/twig/extension.php30
-rw-r--r--phpBB/phpbb/template/twig/extension/avatar.php80
-rw-r--r--phpBB/phpbb/template/twig/extension/config.php64
-rw-r--r--phpBB/phpbb/template/twig/extension/username.php84
-rw-r--r--phpBB/phpbb/template/twig/lexer.php16
-rw-r--r--phpBB/phpbb/template/twig/loader.php8
-rw-r--r--phpBB/phpbb/template/twig/node/definenode.php2
-rw-r--r--phpBB/phpbb/template/twig/node/includeasset.php20
-rw-r--r--phpBB/phpbb/template/twig/node/includephp.php6
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/defineparser.php4
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/event.php17
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/includecss.php4
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/includejs.php4
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/includeparser.php2
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/includephp.php17
-rw-r--r--phpBB/phpbb/template/twig/tokenparser/php.php17
16 files changed, 321 insertions, 54 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]);
+ }
}
diff --git a/phpBB/phpbb/template/twig/extension/avatar.php b/phpBB/phpbb/template/twig/extension/avatar.php
new file mode 100644
index 0000000000..7a17fd4b42
--- /dev/null
+++ b/phpBB/phpbb/template/twig/extension/avatar.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\template\twig\extension;
+
+class avatar extends \Twig_Extension
+{
+ /**
+ * Get the name of this extension
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'avatar';
+ }
+
+ /**
+ * Returns a list of global functions to add to the existing list.
+ *
+ * @return array An array of global functions
+ */
+ public function getFunctions()
+ {
+ return array(
+ new \Twig_SimpleFunction('avatar', array($this, 'get_avatar')),
+ );
+ }
+
+ /**
+ * Get avatar for placing into templates.
+ *
+ * How to use in a template:
+ * - {{ avatar('mode', row, alt, ignore_config, lazy) }}
+ *
+ * The mode and row (group_row or user_row) are required.
+ * The other fields (alt|ignore_config|lazy) are optional.
+ *
+ * @uses \phpbb_get_group_avatar()
+ * @uses \phpbb_get_user_avatar()
+ *
+ * @return string The avatar HTML for the specified mode
+ */
+ public function get_avatar()
+ {
+ $args = func_get_args();
+
+ $mode = (string) $args[0];
+ $row = (array) $args[1];
+ $alt = isset($args[2]) ? (string) $args[2] : false;
+ $ignore_config = isset($args[3]) ? (bool) $args[3] : false;
+ $lazy = isset($args[4]) ? (bool) $args[4] : false;
+
+ // To prevent having to redefine alt attribute ('USER_AVATAR'|'GROUP_AVATAR'), we check if an alternative has been provided
+ switch ($mode)
+ {
+ case 'group':
+ return $alt ? phpbb_get_group_avatar($row, $alt, $ignore_config, $lazy) : phpbb_get_group_avatar($row);
+ break;
+
+ case 'user':
+ return $alt ? phpbb_get_user_avatar($row, $alt, $ignore_config, $lazy) : phpbb_get_user_avatar($row);
+ break;
+
+ default:
+ return '';
+ break;
+ }
+ }
+}
diff --git a/phpBB/phpbb/template/twig/extension/config.php b/phpBB/phpbb/template/twig/extension/config.php
new file mode 100644
index 0000000000..cbf6e505c5
--- /dev/null
+++ b/phpBB/phpbb/template/twig/extension/config.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\template\twig\extension;
+
+class config extends \Twig_Extension
+{
+ /** @var \phpbb\config\config */
+ protected $config;
+
+ /**
+ * Constructor.
+ *
+ * @param \phpbb\config\config $config Configuration object
+ */
+ public function __construct(\phpbb\config\config $config)
+ {
+ $this->config = $config;
+ }
+
+ /**
+ * Get the name of this extension
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'config';
+ }
+
+ /**
+ * Returns a list of global functions to add to the existing list.
+ *
+ * @return array An array of global functions
+ */
+ public function getFunctions()
+ {
+ return array(
+ new \Twig_SimpleFunction('config', array($this, 'get_config')),
+ );
+ }
+
+ /**
+ * Retrieves a configuration value for use in templates.
+ *
+ * @return string The configuration value
+ */
+ public function get_config()
+ {
+ $args = func_get_args();
+
+ return $this->config->offsetGet($args[0]);
+ }
+}
diff --git a/phpBB/phpbb/template/twig/extension/username.php b/phpBB/phpbb/template/twig/extension/username.php
new file mode 100644
index 0000000000..ef149693a0
--- /dev/null
+++ b/phpBB/phpbb/template/twig/extension/username.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\template\twig\extension;
+
+class username extends \Twig_Extension
+{
+ /**
+ * Get the name of this extension
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'username';
+ }
+
+ /**
+ * Returns a list of global functions to add to the existing list.
+ *
+ * @return array An array of global functions
+ */
+ public function getFunctions()
+ {
+ return array(
+ new \Twig_SimpleFunction('username', array($this, 'get_username')),
+ );
+ }
+
+ /**
+ * Get username details for placing into templates.
+ *
+ * How to use in a template:
+ * - {{ username('mode', user_id, username, user_colour, guest_username, custom_profile_url) }}
+ * - {{ username('mode', user_row, guest_username, custom_profile_url) }}
+ * It's possible to provide the user identifier, name and colour separately,
+ * or provide the entire user row at once as an array.
+ *
+ * The mode, user_id and username are required (separately or through a user row).
+ * The other fields (user_colour|guest_username|custom_profile_url) are optional.
+ *
+ * @uses \get_username_string()
+ *
+ * @return string A string based on what is wanted depending on $mode
+ */
+ public function get_username()
+ {
+ $args = func_get_args();
+
+ $mode = $args[0];
+ $user = $args[1];
+
+ // If the entire user row is provided
+ if (is_array($user))
+ {
+ $user_id = isset($user['user_id']) ? $user['user_id'] : '';
+ $username = isset($user['username']) ? $user['username'] : '';
+ $user_colour = isset($user['user_colour']) ? $user['user_colour'] : '';
+ $guest_username = isset($args[2]) ? $args[2] : false;
+ $custom_profile_url = isset($args[3]) ? $args[3] : false;
+ }
+ else
+ {
+ // Options are provided separately
+ $user_id = $user;
+ $username = $args[2];
+ $user_colour = isset($args[3]) ? $args[3] : '';
+ $guest_username = isset($args[4]) ? $args[4] : false;
+ $custom_profile_url = isset($args[5]) ? $args[5] : false;
+ }
+
+ return get_username_string($mode, $user_id, $username, $user_colour, $guest_username, $custom_profile_url);
+ }
+}
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php
index d0bcfa615e..6615a46067 100644
--- a/phpBB/phpbb/template/twig/lexer.php
+++ b/phpBB/phpbb/template/twig/lexer.php
@@ -15,20 +15,10 @@ namespace phpbb\template\twig;
class lexer extends \Twig_Lexer
{
- public function set_environment(\Twig_Environment $env)
+ public function tokenize(\Twig_Source $source)
{
- $this->env = $env;
- }
-
- public function tokenize($code, $filename = null)
- {
- // Handle \Twig_Source format input
- if ($code instanceof \Twig_Source)
- {
- $source = $code;
- $code = $source->getCode();
- $filename = $source->getName();
- }
+ $code = $source->getCode();
+ $filename = $source->getName();
// Our phpBB tags
// Commented out tokens are handled separately from the main replace
diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php
index c13e3ee298..0f193dbe59 100644
--- a/phpBB/phpbb/template/twig/loader.php
+++ b/phpBB/phpbb/template/twig/loader.php
@@ -35,7 +35,7 @@ class loader extends \Twig_Loader_Filesystem
{
$this->filesystem = $filesystem;
- parent::__construct($paths, $this->filesystem->realpath(dirname(__FILE__)));
+ parent::__construct($paths, __DIR__);
}
/**
@@ -116,7 +116,7 @@ class loader extends \Twig_Loader_Filesystem
* Override for Twig_Loader_Filesystem::findTemplate to add support
* for loading from safe directories.
*/
- protected function findTemplate($name)
+ protected function findTemplate($name, $throw = true)
{
$name = (string) $name;
@@ -132,12 +132,12 @@ class loader extends \Twig_Loader_Filesystem
// First, find the template name. The override above of validateName
// causes the validateName process to be skipped for this call
- $file = parent::findTemplate($name);
+ $file = parent::findTemplate($name, $throw);
try
{
// Try validating the name (which may throw an exception)
- parent::validateName($name);
+ $this->validateName($name);
}
catch (\Twig_Error_Loader $e)
{
diff --git a/phpBB/phpbb/template/twig/node/definenode.php b/phpBB/phpbb/template/twig/node/definenode.php
index ddbd151d20..1c51596916 100644
--- a/phpBB/phpbb/template/twig/node/definenode.php
+++ b/phpBB/phpbb/template/twig/node/definenode.php
@@ -16,7 +16,7 @@ namespace phpbb\template\twig\node;
class definenode extends \Twig_Node
{
- public function __construct($capture, \Twig_NodeInterface $name, \Twig_NodeInterface $value, $lineno, $tag = null)
+ public function __construct($capture, \Twig_Node $name, \Twig_Node $value, $lineno, $tag = null)
{
parent::__construct(array('name' => $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag);
}
diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php
index 12034b7820..69bfd58803 100644
--- a/phpBB/phpbb/template/twig/node/includeasset.php
+++ b/phpBB/phpbb/template/twig/node/includeasset.php
@@ -15,15 +15,11 @@ namespace phpbb\template\twig\node;
abstract class includeasset extends \Twig_Node
{
- /** @var \Twig_Environment */
- protected $environment;
-
- public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $tag = null)
+ public function __construct(\Twig_Node_Expression $expr, $lineno, $tag = null)
{
- $this->environment = $environment;
-
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
+
/**
* Compiles the node to PHP.
*
@@ -33,20 +29,18 @@ abstract class includeasset extends \Twig_Node
{
$compiler->addDebugInfo($this);
- $config = $this->environment->get_phpbb_config();
-
$compiler
->write("\$asset_file = ")
->subcompile($this->getNode('expr'))
->raw(";\n")
- ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper(), \$this->getEnvironment()->get_filesystem());\n")
+ ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->env->get_path_helper(), \$this->env->get_filesystem());\n")
->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n")
->indent()
->write("\$asset_path = \$asset->get_path();")
- ->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n")
+ ->write("\$local_file = \$this->env->get_phpbb_root_path() . \$asset_path;\n")
->write("if (!file_exists(\$local_file)) {\n")
->indent()
- ->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n")
+ ->write("\$local_file = \$this->env->findTemplate(\$asset_path);\n")
->write("\$asset->set_path(\$local_file, true);\n")
->outdent()
->write("}\n")
@@ -55,10 +49,10 @@ abstract class includeasset extends \Twig_Node
->write("\n")
->write("if (\$asset->is_relative()) {\n")
->indent()
- ->write("\$asset->add_assets_version('{$config['assets_version']}');\n")
+ ->write("\$asset->add_assets_version(\$this->env->get_phpbb_config()['assets_version']);\n")
->outdent()
->write("}\n")
- ->write("\$this->getEnvironment()->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);")
+ ->write("\$this->env->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);")
;
}
diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php
index 76182c2f84..0cf95abe99 100644
--- a/phpBB/phpbb/template/twig/node/includephp.php
+++ b/phpBB/phpbb/template/twig/node/includephp.php
@@ -63,15 +63,15 @@ class includephp extends \Twig_Node
// Absolute path specified
->write("require(\$location);\n")
->outdent()
- ->write("} else if (file_exists(\$this->getEnvironment()->get_phpbb_root_path() . \$location)) {\n")
+ ->write("} else if (file_exists(\$this->env->get_phpbb_root_path() . \$location)) {\n")
->indent()
// PHP file relative to phpbb_root_path
- ->write("require(\$this->getEnvironment()->get_phpbb_root_path() . \$location);\n")
+ ->write("require(\$this->env->get_phpbb_root_path() . \$location);\n")
->outdent()
->write("} else {\n")
->indent()
// Local path (behaves like INCLUDE)
- ->write("require(\$this->getEnvironment()->getLoader()->getCacheKey(\$location));\n")
+ ->write("require(\$this->env->getLoader()->getCacheKey(\$location));\n")
->outdent()
->write("}\n")
;
diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php
index b755836ccd..6285091e94 100644
--- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php
+++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php
@@ -21,7 +21,7 @@ class defineparser extends \Twig_TokenParser
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
* @throws \Twig_Error_Syntax
* @throws \phpbb\template\twig\node\definenode
*/
@@ -41,7 +41,7 @@ class defineparser extends \Twig_TokenParser
{
// This would happen if someone improperly formed their DEFINE syntax
// e.g. <!-- DEFINE $VAR = foo -->
- throw new \Twig_Error_Syntax('Invalid DEFINE', $token->getLine(), $this->parser->getFilename());
+ throw new \Twig_Error_Syntax('Invalid DEFINE', $token->getLine(), $this->parser->getStream()->getSourceContext()->getPath());
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
diff --git a/phpBB/phpbb/template/twig/tokenparser/event.php b/phpBB/phpbb/template/twig/tokenparser/event.php
index f73ef4ae25..92ecff4a74 100644
--- a/phpBB/phpbb/template/twig/tokenparser/event.php
+++ b/phpBB/phpbb/template/twig/tokenparser/event.php
@@ -15,12 +15,25 @@ namespace phpbb\template\twig\tokenparser;
class event extends \Twig_TokenParser
{
+ /** @var \phpbb\template\twig\environment */
+ protected $environment;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\template\twig\environment $environment
+ */
+ public function __construct(\phpbb\template\twig\environment $environment)
+ {
+ $this->environment = $environment;
+ }
+
/**
* Parses a token and returns a node.
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
@@ -29,7 +42,7 @@ class event extends \Twig_TokenParser
$stream = $this->parser->getStream();
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
- return new \phpbb\template\twig\node\event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ return new \phpbb\template\twig\node\event($expr, $this->environment, $token->getLine(), $this->getTag());
}
/**
diff --git a/phpBB/phpbb/template/twig/tokenparser/includecss.php b/phpBB/phpbb/template/twig/tokenparser/includecss.php
index 1f30811754..f7e55a46fb 100644
--- a/phpBB/phpbb/template/twig/tokenparser/includecss.php
+++ b/phpBB/phpbb/template/twig/tokenparser/includecss.php
@@ -20,7 +20,7 @@ class includecss extends \Twig_TokenParser
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
@@ -29,7 +29,7 @@ class includecss extends \Twig_TokenParser
$stream = $this->parser->getStream();
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
- return new \phpbb\template\twig\node\includecss($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ return new \phpbb\template\twig\node\includecss($expr, $token->getLine(), $this->getTag());
}
/**
diff --git a/phpBB/phpbb/template/twig/tokenparser/includejs.php b/phpBB/phpbb/template/twig/tokenparser/includejs.php
index 4b67d2c468..598ea0a70d 100644
--- a/phpBB/phpbb/template/twig/tokenparser/includejs.php
+++ b/phpBB/phpbb/template/twig/tokenparser/includejs.php
@@ -20,7 +20,7 @@ class includejs extends \Twig_TokenParser
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
@@ -29,7 +29,7 @@ class includejs extends \Twig_TokenParser
$stream = $this->parser->getStream();
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
- return new \phpbb\template\twig\node\includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ return new \phpbb\template\twig\node\includejs($expr, $token->getLine(), $this->getTag());
}
/**
diff --git a/phpBB/phpbb/template/twig/tokenparser/includeparser.php b/phpBB/phpbb/template/twig/tokenparser/includeparser.php
index aa7236aaa6..2fba4ac4c4 100644
--- a/phpBB/phpbb/template/twig/tokenparser/includeparser.php
+++ b/phpBB/phpbb/template/twig/tokenparser/includeparser.php
@@ -21,7 +21,7 @@ class includeparser extends \Twig_TokenParser_Include
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php
index 3992636f8c..2fdf396452 100644
--- a/phpBB/phpbb/template/twig/tokenparser/includephp.php
+++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php
@@ -16,12 +16,25 @@ namespace phpbb\template\twig\tokenparser;
class includephp extends \Twig_TokenParser
{
+ /** @var \phpbb\template\twig\environment */
+ protected $environment;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\template\twig\environment $environment
+ */
+ public function __construct(\phpbb\template\twig\environment $environment)
+ {
+ $this->environment = $environment;
+ }
+
/**
* Parses a token and returns a node.
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
@@ -40,7 +53,7 @@ class includephp extends \Twig_TokenParser
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
- return new \phpbb\template\twig\node\includephp($expr, $this->parser->getEnvironment(), $token->getLine(), $ignoreMissing, $this->getTag());
+ return new \phpbb\template\twig\node\includephp($expr, $this->environment, $token->getLine(), $ignoreMissing, $this->getTag());
}
/**
diff --git a/phpBB/phpbb/template/twig/tokenparser/php.php b/phpBB/phpbb/template/twig/tokenparser/php.php
index f11ce35896..3007912b47 100644
--- a/phpBB/phpbb/template/twig/tokenparser/php.php
+++ b/phpBB/phpbb/template/twig/tokenparser/php.php
@@ -15,12 +15,25 @@ namespace phpbb\template\twig\tokenparser;
class php extends \Twig_TokenParser
{
+ /** @var \phpbb\template\twig\environment */
+ protected $environment;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\template\twig\environment $environment
+ */
+ public function __construct(\phpbb\template\twig\environment $environment)
+ {
+ $this->environment = $environment;
+ }
+
/**
* Parses a token and returns a node.
*
* @param \Twig_Token $token A Twig_Token instance
*
- * @return \Twig_NodeInterface A Twig_NodeInterface instance
+ * @return \Twig_Node A Twig_Node instance
*/
public function parse(\Twig_Token $token)
{
@@ -32,7 +45,7 @@ class php extends \Twig_TokenParser
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
- return new \phpbb\template\twig\node\php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
+ return new \phpbb\template\twig\node\php($body, $this->environment, $token->getLine(), $this->getTag());
}
public function decideEnd(\Twig_Token $token)