diff options
author | MateBartus <mate.bartus@gmail.com> | 2015-05-01 19:04:21 +0200 |
---|---|---|
committer | MateBartus <mate.bartus@gmail.com> | 2015-05-05 19:16:49 +0200 |
commit | 7b301e22f32e9209bb4e3ea17a5637a84a4ef908 (patch) | |
tree | 20c56c1c0982976a0234409bdd7bf05050353545 /phpBB/phpbb/template | |
parent | de687f32ed8df438cb798d98f1a5dda7a5ac76dc (diff) | |
download | forums-7b301e22f32e9209bb4e3ea17a5637a84a4ef908.tar forums-7b301e22f32e9209bb4e3ea17a5637a84a4ef908.tar.gz forums-7b301e22f32e9209bb4e3ea17a5637a84a4ef908.tar.bz2 forums-7b301e22f32e9209bb4e3ea17a5637a84a4ef908.tar.xz forums-7b301e22f32e9209bb4e3ea17a5637a84a4ef908.zip |
[ticket/13804] Make template's user dependency optional
PHPBB3-13804
Diffstat (limited to 'phpBB/phpbb/template')
-rw-r--r-- | phpBB/phpbb/template/exception/user_object_not_available.php | 22 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/twig.php | 24 |
2 files changed, 43 insertions, 3 deletions
diff --git a/phpBB/phpbb/template/exception/user_object_not_available.php b/phpBB/phpbb/template/exception/user_object_not_available.php new file mode 100644 index 0000000000..62fd2743c1 --- /dev/null +++ b/phpBB/phpbb/template/exception/user_object_not_available.php @@ -0,0 +1,22 @@ +<?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\exception; + +/** + * This exception is thrown when the user object was not set but it is required by the called method + */ +class user_object_not_available extends \phpbb\exception\runtime_exception +{ + +} diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 0e4c619029..ab349cc740 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -13,6 +13,8 @@ namespace phpbb\template\twig; +use phpbb\template\exception\user_object_not_available; + /** * Twig Template class. */ @@ -76,14 +78,14 @@ class twig extends \phpbb\template\base * * @param \phpbb\path_helper $path_helper * @param \phpbb\config\config $config - * @param \phpbb\user $user * @param \phpbb\template\context $context template context * @param \phpbb\template\twig\environment $twig_environment * @param string $cache_path + * @param \phpbb\user|null $user * @param array|\ArrayAccess $extensions * @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked */ - public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, $extensions = array(), \phpbb\extension\manager $extension_manager = null) + public function __construct(\phpbb\path_helper $path_helper, $config, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, \phpbb\user $user = null, $extensions = array(), \phpbb\extension\manager $extension_manager = null) { $this->path_helper = $path_helper; $this->phpbb_root_path = $path_helper->get_phpbb_root_path(); @@ -126,9 +128,16 @@ class twig extends \phpbb\template\base * Get the style tree of the style preferred by the current user * * @return array Style tree, most specific first + * + * @throws \phpbb\template\exception\user_object_not_available When user service was not set */ public function get_user_style() { + if ($this->user === null) + { + throw new user_object_not_available(); + } + $style_list = array( $this->user->style['style_path'], ); @@ -344,11 +353,20 @@ class twig extends \phpbb\template\base $context_vars['.'][0], // To get normal vars array( 'definition' => new \phpbb\template\twig\definition(), - 'user' => $this->user, 'loops' => $context_vars, // To get loops ) ); + if ($this->user instanceof \phpbb\user) + { + $vars = array_merge( + $vars, + array( + 'user' => $this->user, + ) + ); + } + // cleanup unset($vars['loops']['.']); |