mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge pull request #3581 from MateBartus/ticket/13804
[ticket/13804] Make template's user dependency optional
This commit is contained in:
commit
ba9ac01dc0
14 changed files with 67 additions and 29 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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');
|
||||
|
|
22
phpBB/phpbb/template/exception/user_object_not_available.php
Normal file
22
phpBB/phpbb/template/exception/user_object_not_available.php
Normal file
|
@ -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
|
||||
{
|
||||
|
||||
}
|
|
@ -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']['.']);
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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__) . '/',
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue