aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/default/container/services_twig.yml8
-rw-r--r--phpBB/phpbb/template/twig/extension.php48
-rw-r--r--phpBB/phpbb/template/twig/extension/auth.php91
-rw-r--r--phpBB/phpbb/template/twig/extension/username.php1
-rw-r--r--tests/controller/common_helper_route.php6
-rw-r--r--tests/email/email_parsing_test.php8
-rw-r--r--tests/extension/metadata_manager_test.php4
-rw-r--r--tests/template/template_allfolder_test.php4
-rw-r--r--tests/template/template_events_test.php4
-rw-r--r--tests/template/template_includecss_test.php4
-rw-r--r--tests/template/template_test_case.php4
-rw-r--r--tests/template/template_test_case_with_tree.php4
12 files changed, 77 insertions, 109 deletions
diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml
index f3ad95207d..367886804c 100644
--- a/phpBB/config/default/container/services_twig.yml
+++ b/phpBB/config/default/container/services_twig.yml
@@ -37,19 +37,13 @@ services:
template.twig.extensions.phpbb:
class: phpbb\template\twig\extension
arguments:
+ - '@auth'
- '@template_context'
- '@template.twig.environment'
- '@language'
tags:
- { name: twig.extension }
- template.twig.extensions.auth:
- class: phpbb\template\twig\extension\auth
- arguments:
- - '@auth'
- tags:
- - { name: twig.extension }
-
template.twig.extensions.avatar:
class: phpbb\template\twig\extension\avatar
tags:
diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php
index c5b3db1aaf..5bb0c67291 100644
--- a/phpBB/phpbb/template/twig/extension.php
+++ b/phpBB/phpbb/template/twig/extension.php
@@ -15,6 +15,9 @@ namespace phpbb\template\twig;
class extension extends \Twig_Extension
{
+ /** @var \phpbb\auth\auth */
+ protected $auth;
+
/** @var \phpbb\template\context */
protected $context;
@@ -27,13 +30,14 @@ class extension extends \Twig_Extension
/**
* Constructor
*
+ * @param \phpbb\auth\auth $auth
* @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, \phpbb\template\twig\environment $environment, $language)
+ public function __construct(\phpbb\auth\auth $auth, \phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language)
{
+ $this->auth = $auth;
$this->context = $context;
$this->environment = $environment;
$this->language = $language;
@@ -91,6 +95,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('auth', array($this, 'get_auth')),
+ new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')),
);
}
@@ -198,4 +204,42 @@ class extension extends \Twig_Extension
{
return call_user_func_array([$this->language, 'is_set'], [$key]);
}
+
+ /**
+ * Look up permission option(s).
+ *
+ * How to use in a template:
+ * - {{ auth(options, forum_id) }}
+ *
+ * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
+ * The forum identifier is optional.
+ *
+ * @return bool
+ */
+ public function get_auth()
+ {
+ $args = func_get_args();
+
+ $options = $args[0];
+ $forum_id = isset($args[1]) ? (int) $args[1] : 0;
+
+ return is_array($options) ? $this->auth->acl_gets($options, $forum_id) : $this->auth->acl_get($options, $forum_id);
+ }
+
+ /**
+ * Look up permission option(s) for any forum
+ *
+ * How to use in a template:
+ * - {{ auth_global(options) }}
+ *
+ * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
+ *
+ * @return bool
+ */
+ public function get_auth_global()
+ {
+ $args = func_get_args();
+
+ return $this->auth->acl_getf_global($args);
+ }
}
diff --git a/phpBB/phpbb/template/twig/extension/auth.php b/phpBB/phpbb/template/twig/extension/auth.php
deleted file mode 100644
index 9dbe306782..0000000000
--- a/phpBB/phpbb/template/twig/extension/auth.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?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 auth extends \Twig_Extension
-{
- /** @var \phpbb\auth\auth */
- protected $auth;
-
- /**
- * Constructor.
- *
- * @param \phpbb\auth\auth $auth Authentication object
- */
- public function __construct(\phpbb\auth\auth $auth)
- {
- $this->auth = $auth;
- }
-
- /**
- * Get the name of this extension
- *
- * @return string
- */
- public function getName()
- {
- return 'auth';
- }
-
- /**
- * 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('auth', array($this, 'get_auth')),
- new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')),
- );
- }
-
- /**
- * Look up permission option(s).
- *
- * How to use in a template:
- * - {{ auth(options, forum_id) }}
- *
- * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
- * The forum identifier is optional.
- *
- * @return bool
- */
- public function get_auth()
- {
- $args = func_get_args();
-
- $options = $args[0];
- $forum_id = isset($args[1]) ? (int) $args[1] : 0;
-
- return is_array($options) ? $this->auth->acl_gets($options, $forum_id) : $this->auth->acl_get($options, $forum_id);
- }
-
- /**
- * Look up permission option(s) for any forum
- *
- * How to use in a template:
- * - {{ auth_global(options) }}
- *
- * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_'].
- *
- * @return bool
- */
- public function get_auth_global()
- {
- $args = func_get_args();
-
- return $this->auth->acl_getf_global($args);
- }
-}
diff --git a/phpBB/phpbb/template/twig/extension/username.php b/phpBB/phpbb/template/twig/extension/username.php
index c80396b116..ef149693a0 100644
--- a/phpBB/phpbb/template/twig/extension/username.php
+++ b/phpBB/phpbb/template/twig/extension/username.php
@@ -79,7 +79,6 @@ class username extends \Twig_Extension
$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/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php
index 447c10d10e..3d3578ab43 100644
--- a/tests/controller/common_helper_route.php
+++ b/tests/controller/common_helper_route.php
@@ -74,7 +74,9 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
protected function generate_route_objects()
{
- global $request;
+ global $request, $phpbb_root_path, $phpEx;
+
+ $auth = $this->getMock('\phpbb\auth\auth');
$this->request = new phpbb_mock_request();
$this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER);
@@ -122,7 +124,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, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $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($auth, $context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->extension_manager = new phpbb_mock_extension_manager(
diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php
index 629df9abb6..1b5c6aaa8c 100644
--- a/tests/email/email_parsing_test.php
+++ b/tests/email/email_parsing_test.php
@@ -66,7 +66,15 @@ class phpbb_email_parsing_test extends phpbb_test_case
);
$phpbb_container->set('ext.manager', $extension_manager);
+ $auth = $this->getMock('\phpbb\auth\auth');
$context = new \phpbb\template\context();
+ $twig_extension = new \phpbb\template\twig\extension($auth, $context, $lang);
+ $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension);
+
+ $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container);
+ $twig_extensions_collection->add('template.twig.extensions.phpbb');
+ $phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection);
+
$twig = new \phpbb\template\twig\environment(
$config,
$filesystem,
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index a2f0542979..f2f5dc669e 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -36,6 +36,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{
parent::setUp();
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$this->config = new \phpbb\config\config(array(
'version' => '3.1.0',
));
@@ -111,7 +113,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, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $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($auth, $context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
}
diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php
index a9a8ecc287..60891a3668 100644
--- a/tests/template/template_allfolder_test.php
+++ b/tests/template/template_allfolder_test.php
@@ -26,6 +26,8 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
{
global $phpbb_root_path, $phpEx;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@@ -75,7 +77,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $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($auth, $context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(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 9243390937..e879979803 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -131,6 +131,8 @@ Zeta test event in all',
{
global $phpbb_root_path, $phpEx, $user;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
@@ -169,7 +171,7 @@ Zeta test event in all',
'autoescape' => false,
)
);
- $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $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($auth, $context, $twig, $this->user)), $this->extension_manager);
$twig->setLexer(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 5f9875a556..0f26c095a7 100644
--- a/tests/template/template_includecss_test.php
+++ b/tests/template/template_includecss_test.php
@@ -25,6 +25,8 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
{
global $phpbb_root_path, $phpEx, $user;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
@@ -68,7 +70,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
$twig,
$cache_path,
$this->user,
- array(new \phpbb\template\twig\extension($context, $twig, $this->user)),
+ array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user)),
new phpbb_mock_extension_manager(
dirname(__FILE__) . '/',
array(
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 0389088ec8..f495c93f9d 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -73,6 +73,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
{
global $phpbb_root_path, $phpEx;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@@ -113,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, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)));
+ $this->template = new phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($auth, $context, $twig, $this->user)));
$twig->setLexer(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 c0238b6f03..756bedb042 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -19,6 +19,8 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
{
global $phpbb_root_path, $phpEx, $user;
+ $auth = $this->getMock('\phpbb\auth\auth');
+
$defaults = $this->config_defaults();
$config = new \phpbb\config\config(array_merge($defaults, $new_config));
@@ -56,7 +58,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, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $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($auth, $context, $twig, $this->user)));
$twig->setLexer(new \phpbb\template\twig\lexer($twig));
$this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
}