aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/default/container/services.yml15
-rw-r--r--phpBB/config/default/container/services_twig.yml15
-rw-r--r--phpBB/includes/bbcode.php2
-rw-r--r--phpBB/includes/functions_messenger.php2
-rw-r--r--phpBB/install/index.php7
-rw-r--r--phpBB/phpbb/template/exception/user_object_not_available.php22
-rw-r--r--phpBB/phpbb/template/twig/twig.php19
-rw-r--r--tests/controller/common_helper_route.php2
-rw-r--r--tests/extension/metadata_manager_test.php2
-rw-r--r--tests/template/template_allfolder_test.php2
-rw-r--r--tests/template/template_events_test.php2
-rw-r--r--tests/template/template_includecss_test.php2
-rw-r--r--tests/template/template_test_case.php2
-rw-r--r--tests/template/template_test_case_with_tree.php2
14 files changed, 67 insertions, 29 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']['.']);
diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php
index b938766fa3..44e5e12ab0 100644
--- a/tests/controller/common_helper_route.php
+++ b/tests/controller/common_helper_route.php
@@ -107,7 +107,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
'autoescape' => false,
)
);
- $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
$this->extension_manager = new phpbb_mock_extension_manager(
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index aaaee3b2e5..53bd3d109b 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -111,7 +111,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$lang = new \phpbb\language\language($lang_loader);
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
- $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
}
diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php
index 14a8e9d463..9a0f1f512e 100644
--- a/tests/template/template_allfolder_test.php
+++ b/tests/template/template_allfolder_test.php
@@ -75,7 +75,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
$this->template_path = $this->test_path . '/templates';
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index 285e82188b..54e08652a1 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -169,7 +169,7 @@ Zeta test event in all',
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
+ $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)), $this->extension_manager);
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path));
diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php
index 8c398d992b..062fc9493b 100644
--- a/tests/template/template_includecss_test.php
+++ b/tests/template/template_includecss_test.php
@@ -64,10 +64,10 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
$this->template = new phpbb\template\twig\twig(
$this->phpbb_path_helper,
$config,
- $user,
$context,
$twig,
$cache_path,
+ $this->user,
array(new \phpbb\template\twig\extension($context, $this->user)),
new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index b1826571af..62eea0d361 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -115,7 +115,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
'autoescape' => false,
)
);
- $this->template = new phpbb\template\twig\twig($path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', $this->template_path);
}
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index d0c49006fd..bf5de6b85e 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -56,7 +56,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
'autoescape' => false,
)
);
- $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $user, $context, $twig, $cache_path, array(new \phpbb\template\twig\extension($context, $this->user)));
+ $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $this->user)));
$container->set('template.twig.lexer', new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
}