diff options
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/config/default/container/services.yml | 15 | ||||
-rw-r--r-- | phpBB/config/default/container/services_twig.yml | 15 | ||||
-rw-r--r-- | phpBB/includes/bbcode.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_messenger.php | 2 | ||||
-rw-r--r-- | phpBB/install/index.php | 7 | ||||
-rw-r--r-- | phpBB/phpbb/template/exception/user_object_not_available.php | 22 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/twig.php | 19 |
7 files changed, 60 insertions, 22 deletions
diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 95d624a8ae..6577a44195 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -168,21 +168,6 @@ services: request_stack: class: Symfony\Component\HttpFoundation\RequestStack - template: - class: phpbb\template\twig\twig - arguments: - - @path_helper - - @config - - @user - - @template_context - - @template.twig.environment - - %core.template.cache_path% - - @template.twig.extensions.collection - - @ext.manager - - template_context: - class: phpbb\template\context - upload_imagesize: class: fastImageSize\fastImageSize diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index 9ab004731e..d8e1ae0769 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -47,3 +47,18 @@ services: template.twig.extensions.debug: class: Twig_Extension_Debug + + template: + class: phpbb\template\twig\twig + arguments: + - @path_helper + - @config + - @template_context + - @template.twig.environment + - %core.template.cache_path% + - @user + - @template.twig.extensions.collection + - @ext.manager + + template_context: + class: phpbb\template\context diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index 150157e275..24eaddf067 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -138,7 +138,6 @@ class bbcode $template = new \phpbb\template\twig\twig( $phpbb_container->get('path_helper'), $phpbb_container->get('config'), - $phpbb_container->get('user'), new \phpbb\template\context(), new \phpbb\template\twig\environment( $phpbb_container->get('config'), @@ -152,6 +151,7 @@ class bbcode ) ), $phpbb_container->getParameter('core.root_path') . 'cache/', + $phpbb_container->get('user'), $phpbb_container->get('template.twig.extensions.collection'), $phpbb_extension_manager ); diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 4cbe1eb425..6abfb40b01 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -633,7 +633,6 @@ class messenger $this->template = new \phpbb\template\twig\twig( $phpbb_container->get('path_helper'), $phpbb_container->get('config'), - $phpbb_container->get('user'), new \phpbb\template\context(), new \phpbb\template\twig\environment( $phpbb_container->get('config'), @@ -647,6 +646,7 @@ class messenger ) ), $phpbb_container->getParameter('core.root_path') . 'cache/', + $phpbb_container->get('user'), $phpbb_container->get('template.twig.extensions.collection'), $phpbb_extension_manager ); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 657825ca39..056c827669 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -138,6 +138,7 @@ $phpbb_container_builder->set_custom_parameters(array( $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->register('dbal.conn.driver')->setSynthetic(true); $phpbb_container->register('template.twig.environment')->setSynthetic(true); +$phpbb_container->register('language.loader')->setSynthetic(true); $phpbb_container->compile(); $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver')); @@ -288,16 +289,18 @@ $twig_environment = new \phpbb\template\twig\environment( $phpbb_container->get('template.twig.loader') ); +$language_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $phpbb_container->set('template.twig.environment', $twig_environment); +$phpbb_container->set('language.loader', $language_loader); $twig_context = new \phpbb\template\context(); $template = new \phpbb\template\twig\twig( $phpbb_path_helper, $config, - $user, $twig_context, $twig_environment, $cache_path, - array(new \phpbb\template\twig\extension($twig_context, $user)) + $user, + array($phpbb_container->get('template.twig.extensions.phpbb')) ); $paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style'); 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..6b3cf32bc8 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,15 @@ 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['user'] = $this->user; + } + // cleanup unset($vars['loops']['.']); |