diff options
Diffstat (limited to 'phpBB/phpbb/template')
| -rw-r--r-- | phpBB/phpbb/template/twig/environment.php | 30 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/lexer.php | 5 | ||||
| -rw-r--r-- | phpBB/phpbb/template/twig/twig.php | 39 | 
3 files changed, 44 insertions, 30 deletions
diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 476ffd935e..0ba7a265e4 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -21,6 +21,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,24 +41,49 @@ 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'); +			$this->lexer->set_environment($this); +		} + +		return $this->lexer; +	} + + +	/**  	* Get the list of enabled phpBB extensions  	*  	* Used in EVENT node diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index c5dc7273ba..a7848738bb 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -15,6 +15,11 @@ namespace phpbb\template\twig;  class lexer extends \Twig_Lexer  { +	public function set_environment(\Twig_Environment $env) +	{ +		$this->env = $env; +	} +  	public function tokenize($code, $filename = null)  	{  		// Our phpBB tags diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index a3b002f350..2a8fb76b90 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -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/'))  | 
