1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

Merge remote-tracking branch 'github-nicofuma/ticket/11649' into develop

* github-nicofuma/ticket/11649:
  [ticket/11649] Fix coding style
  [ticket/11649] Expose Twig through the container
This commit is contained in:
Nils Adermann
2014-08-09 17:17:57 +02:00
9 changed files with 194 additions and 47 deletions

View File

@@ -10,6 +10,7 @@ imports:
- { resource: mimetype_guessers.yml }
- { resource: passwords.yml }
- { resource: profilefields.yml }
- { resource: twig.yml }
services:
acl.permissions:
@@ -339,6 +340,9 @@ services:
- @config
- @user
- @template_context
- @template.twig.environment
- %core.template.cache_path%
- @template.twig.extensions.collection
- @ext.manager
template_context:

36
phpBB/config/twig.yml Normal file
View File

@@ -0,0 +1,36 @@
parameters:
core.template.cache_path: %core.root_path%cache/twig/
services:
template.twig.environment:
class: phpbb\template\twig\environment
arguments:
- @config
- @path_helper
- @service_container
- %core.template.cache_path%
- @ext.manager
- @template.twig.loader
template.twig.lexer:
class: phpbb\template\twig\lexer
arguments:
- @template.twig.environment
template.twig.loader:
class: phpbb\template\twig\loader
template.twig.extensions.collection:
class: phpbb\di\service_collection
arguments:
- @service_container
tags:
- { name: service_collection, tag: twig.extension }
template.twig.extensions.phpbb:
class: phpbb\template\twig\extension
arguments:
- @template_context
- @user
tags:
- { name: twig.extension }

View File

@@ -13,6 +13,9 @@
namespace phpbb\template\twig;
use Twig_Lexer;
use Twig_LexerInterface;
class environment extends \Twig_Environment
{
/** @var \phpbb\config\config */
@@ -21,6 +24,9 @@ class environment extends \Twig_Environment
/** @var \phpbb\path_helper */
protected $phpbb_path_helper;
/** @var \Symfony\Component\DependencyInjection\ContainerInterface */
protected $container;
/** @var \phpbb\extension\manager */
protected $extension_manager;
@@ -38,23 +44,47 @@ class environment extends \Twig_Environment
*
* @param \phpbb\config\config $phpbb_config The phpBB configuration
* @param \phpbb\path_helper $path_helper phpBB path helper
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container
* @param string $cache_path The path to the cache directory
* @param \phpbb\extension\manager $extension_manager phpBB extension manager
* @param \Twig_LoaderInterface $loader Twig loader interface
* @param array $options Array of options to pass to Twig
*/
public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
{
$this->phpbb_config = $phpbb_config;
$this->phpbb_path_helper = $path_helper;
$this->extension_manager = $extension_manager;
$this->container = $container;
$this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path();
$this->web_root_path = $this->phpbb_path_helper->get_web_root_path();
$options = array_merge(array(
'cache' => (defined('IN_INSTALL')) ? false : $cache_path,
'debug' => defined('DEBUG'),
'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'],
'autoescape' => false,
), $options);
return parent::__construct($loader, $options);
}
/**
* {@inheritdoc}
*/
public function getLexer()
{
if (null === $this->lexer)
{
$this->lexer = $this->container->get('template.twig.lexer');
}
return $this->lexer;
}
/**
* Get the list of enabled phpBB extensions
*

View File

@@ -78,9 +78,12 @@ class twig extends \phpbb\template\base
* @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 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\extension\manager $extension_manager = null)
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)
{
$this->path_helper = $path_helper;
$this->phpbb_root_path = $path_helper->get_phpbb_root_path();
@@ -89,35 +92,13 @@ class twig extends \phpbb\template\base
$this->user = $user;
$this->context = $context;
$this->extension_manager = $extension_manager;
$this->cachepath = $cache_path;
$this->twig = $twig_environment;
$this->cachepath = $this->phpbb_root_path . 'cache/twig/';
// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
$loader = new \phpbb\template\twig\loader('');
$this->twig = new \phpbb\template\twig\environment(
$this->config,
$this->path_helper,
$this->extension_manager,
$loader,
array(
'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath,
'debug' => defined('DEBUG'),
'auto_reload' => (bool) $this->config['load_tplcompile'],
'autoescape' => false,
)
);
$this->twig->addExtension(
new \phpbb\template\twig\extension(
$this->context,
$this->user
)
);
$lexer = new \phpbb\template\twig\lexer($this->twig);
$this->twig->setLexer($lexer);
foreach ($extensions as $extension)
{
$this->twig->addExtension($extension);
}
// Add admin namespace
if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/'))