From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/template/twig/environment.php | 140 ++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 phpBB/phpbb/template/twig/environment.php (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php new file mode 100644 index 0000000000..b60cd72325 --- /dev/null +++ b/phpBB/phpbb/template/twig/environment.php @@ -0,0 +1,140 @@ + path) + * @param string $phpbb_root_path + * @param Twig_LoaderInterface $loader + * @param array $options Array of options to pass to Twig + */ + public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) + { + $this->phpbb_config = $phpbb_config; + $this->phpbb_extensions = $phpbb_extensions; + $this->phpbb_root_path = $phpbb_root_path; + + return parent::__construct($loader, $options); + } + + /** + * Get the list of enabled phpBB extensions + * + * Used in EVENT node + * + * @return array + */ + public function get_phpbb_extensions() + { + return $this->phpbb_extensions; + } + + /** + * Get phpBB config + * + * @return phpbb_config + */ + public function get_phpbb_config() + { + return $this->phpbb_config; + } + + /** + * Get the phpBB root path + * + * @return string + */ + public function get_phpbb_root_path() + { + return $this->phpbb_root_path; + } + + /** + * Get the namespace look up order + * + * @return array + */ + public function getNamespaceLookUpOrder() + { + return $this->namespace_look_up_order; + } + + /** + * Set the namespace look up order to load templates from + * + * @param array $namespace + * @return Twig_Environment + */ + public function setNamespaceLookUpOrder($namespace) + { + $this->namespace_look_up_order = $namespace; + + return $this; + } + + /** + * Loads a template by name. + * + * @param string $name The template name + * @param integer $index The index if it is an embedded template + * @return Twig_TemplateInterface A template instance representing the given template name + */ + public function loadTemplate($name, $index = null) + { + if (strpos($name, '@') === false) + { + foreach ($this->getNamespaceLookUpOrder() as $namespace) + { + try + { + if ($namespace === '__main__') + { + return parent::loadTemplate($name, $index); + } + + return parent::loadTemplate('@' . $namespace . '/' . $name, $index); + } + catch (Twig_Error_Loader $e) + { + } + } + + // We were unable to load any templates + throw $e; + } + else + { + return parent::loadTemplate($name, $index); + } + } +} -- cgit v1.2.1 From 423357581415c7c10ed0ac51284014e839881bac Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 2 Sep 2013 13:54:42 -0500 Subject: [ticket/11822] Use namespace lookup order for asset loading PHPBB3-11822 --- phpBB/phpbb/template/twig/environment.php | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b60cd72325..9a40dc2b15 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -137,4 +137,39 @@ class phpbb_template_twig_environment extends Twig_Environment return parent::loadTemplate($name, $index); } } + + /** + * Finds a template by name. + * + * @param string $name The template name + * @return string + */ + public function findTemplate($name) + { + if (strpos($name, '@') === false) + { + foreach ($this->getNamespaceLookUpOrder() as $namespace) + { + try + { + if ($namespace === '__main__') + { + return parent::getLoader()->getCacheKey($name); + } + + return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name); + } + catch (Twig_Error_Loader $e) + { + } + } + + // We were unable to load any templates + throw $e; + } + else + { + return parent::getLoader()->getCacheKey($name); + } + } } -- cgit v1.2.1 From b4a374dc73eda55db1c67b87bd65a73f79411ef5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 10:58:03 -0500 Subject: [ticket/11832] Fix INCLUDE(JS/CSS) PHPBB3-11832 --- phpBB/phpbb/template/twig/environment.php | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 9a40dc2b15..612519db69 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -23,9 +23,15 @@ class phpbb_template_twig_environment extends Twig_Environment /** @var phpbb_config */ protected $phpbb_config; + /** @var phpbb_filesystem */ + protected $phpbb_filesystem; + /** @var string */ protected $phpbb_root_path; + /** @var string */ + protected $web_root_path; + /** @var array **/ protected $namespace_look_up_order = array('__main__'); @@ -38,11 +44,14 @@ class phpbb_template_twig_environment extends Twig_Environment * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, $phpbb_extensions, phpbb_filesystem $phpbb_filesystem, Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->phpbb_extensions = $phpbb_extensions; - $this->phpbb_root_path = $phpbb_root_path; + + $this->phpbb_filesystem = $phpbb_filesystem; + $this->phpbb_root_path = $this->phpbb_filesystem->get_phpbb_root_path(); + $this->web_root_path = $this->phpbb_filesystem->get_web_root_path(); return parent::__construct($loader, $options); } @@ -79,6 +88,26 @@ class phpbb_template_twig_environment extends Twig_Environment return $this->phpbb_root_path; } + /** + * Get the web root path + * + * @return string + */ + public function get_web_root_path() + { + return $this->web_root_path; + } + + /** + * Get the phpbb_filesystem object + * + * @return phpbb_filesystem + */ + public function get_filesystem() + { + return $this->phpbb_filesystem; + } + /** * Get the namespace look up order * -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/template/twig/environment.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b60cd72325..64f3ace52d 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\template\twig; + /** * @ignore */ @@ -15,12 +17,12 @@ if (!defined('IN_PHPBB')) exit; } -class phpbb_template_twig_environment extends Twig_Environment +class environment extends \Twig_Environment { /** @var array */ protected $phpbb_extensions; - /** @var phpbb_config */ + /** @var \phpbb\config\config */ protected $phpbb_config; /** @var string */ @@ -32,13 +34,13 @@ class phpbb_template_twig_environment extends Twig_Environment /** * Constructor * - * @param phpbb_config $phpbb_config + * @param \phpbb\config\config $phpbb_config * @param array $phpbb_extensions Array of enabled extensions (name => path) * @param string $phpbb_root_path * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->phpbb_extensions = $phpbb_extensions; @@ -62,7 +64,7 @@ class phpbb_template_twig_environment extends Twig_Environment /** * Get phpBB config * - * @return phpbb_config + * @return \phpbb\config\config */ public function get_phpbb_config() { @@ -124,7 +126,7 @@ class phpbb_template_twig_environment extends Twig_Environment return parent::loadTemplate('@' . $namespace . '/' . $name, $index); } - catch (Twig_Error_Loader $e) + catch (\Twig_Error_Loader $e) { } } -- cgit v1.2.1 From 1adcbccc09dfb890a39939202b4e520a2458407a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 17 Sep 2013 18:56:47 +0200 Subject: [ticket/11700] Replace some leftover phpbb_filesystem uses PHPBB3-11700 --- phpBB/phpbb/template/twig/environment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 132dae4762..e0ee23dcd9 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -25,7 +25,7 @@ class environment extends \Twig_Environment /** @var \phpbb\config\config */ protected $phpbb_config; - /** @var phpbb_filesystem */ + /** @var \phpbb\filesystem */ protected $phpbb_filesystem; /** @var string */ @@ -104,7 +104,7 @@ class environment extends \Twig_Environment /** * Get the phpbb_filesystem object * - * @return phpbb_filesystem + * @return \phpbb\filesystem */ public function get_filesystem() { -- cgit v1.2.1 From 7525c49d454e1ff4a156709ea9ecc1dc0b28dd6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2013 15:34:44 +0200 Subject: [ticket/11852] Split filesystem and path_helper into 2 classes PHPBB3-11852 --- phpBB/phpbb/template/twig/environment.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index e0ee23dcd9..a6c0e476f0 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -25,8 +25,8 @@ class environment extends \Twig_Environment /** @var \phpbb\config\config */ protected $phpbb_config; - /** @var \phpbb\filesystem */ - protected $phpbb_filesystem; + /** @var \phpbb\path_helper */ + protected $phpbb_path_helper; /** @var string */ protected $phpbb_root_path; @@ -42,19 +42,19 @@ class environment extends \Twig_Environment * * @param \phpbb\config\config $phpbb_config * @param array $phpbb_extensions Array of enabled extensions (name => path) - * @param \phpbb\filesystem + * @param \phpbb\path_helper * @param string $phpbb_root_path * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, $phpbb_extensions, \phpbb\filesystem $phpbb_filesystem, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, $phpbb_extensions, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->phpbb_extensions = $phpbb_extensions; - $this->phpbb_filesystem = $phpbb_filesystem; - $this->phpbb_root_path = $this->phpbb_filesystem->get_phpbb_root_path(); - $this->web_root_path = $this->phpbb_filesystem->get_web_root_path(); + $this->phpbb_path_helper = $path_helper; + $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); + $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); return parent::__construct($loader, $options); } @@ -102,13 +102,13 @@ class environment extends \Twig_Environment } /** - * Get the phpbb_filesystem object + * Get the phpbb path helper object * - * @return \phpbb\filesystem + * @return \phpbb\path_helper */ - public function get_filesystem() + public function get_path_helper() { - return $this->phpbb_filesystem; + return $this->phpbb_path_helper; } /** -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/template/twig/environment.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index a6c0e476f0..24bd55b3c5 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class environment extends \Twig_Environment { /** @var array */ -- cgit v1.2.1 From 75c54f7f5e4170ad6d826b1d20725da712098c43 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 27 Jan 2014 18:51:39 -0800 Subject: [ticket/12100] Ensure enabled extensions are fresh in Twig environment PHPBB3-12100 --- phpBB/phpbb/template/twig/environment.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 24bd55b3c5..53e3785e6d 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -11,8 +11,8 @@ namespace phpbb\template\twig; class environment extends \Twig_Environment { - /** @var array */ - protected $phpbb_extensions; + /** @var \phpbb\extension\manager */ + protected $extension_manager; /** @var \phpbb\config\config */ protected $phpbb_config; @@ -33,16 +33,16 @@ class environment extends \Twig_Environment * Constructor * * @param \phpbb\config\config $phpbb_config - * @param array $phpbb_extensions Array of enabled extensions (name => path) + * @param \phpbb\extension\manager * @param \phpbb\path_helper * @param string $phpbb_root_path * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, $phpbb_extensions, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, \phpbb\extension\manager $extension_manager = null, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; - $this->phpbb_extensions = $phpbb_extensions; + $this->extension_manager = $extension_manager; $this->phpbb_path_helper = $path_helper; $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); @@ -60,7 +60,7 @@ class environment extends \Twig_Environment */ public function get_phpbb_extensions() { - return $this->phpbb_extensions; + return ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(); } /** -- cgit v1.2.1 From d3ce584dc785cb033fb2b4f0808a62c51af4791e Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 27 Jan 2014 20:38:15 -0800 Subject: [ticket/12100] Re-order arguments in template environment constructor PHPBB3-12100 --- phpBB/phpbb/template/twig/environment.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 53e3785e6d..aa55f1e011 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -11,15 +11,15 @@ namespace phpbb\template\twig; class environment extends \Twig_Environment { - /** @var \phpbb\extension\manager */ - protected $extension_manager; - /** @var \phpbb\config\config */ protected $phpbb_config; /** @var \phpbb\path_helper */ protected $phpbb_path_helper; + /** @var \phpbb\extension\manager */ + protected $extension_manager; + /** @var string */ protected $phpbb_root_path; @@ -33,18 +33,19 @@ class environment extends \Twig_Environment * Constructor * * @param \phpbb\config\config $phpbb_config - * @param \phpbb\extension\manager * @param \phpbb\path_helper + * @param \phpbb\extension\manager * @param string $phpbb_root_path * @param Twig_LoaderInterface $loader * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, \phpbb\extension\manager $extension_manager = null, \phpbb\path_helper $path_helper, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; - $this->extension_manager = $extension_manager; $this->phpbb_path_helper = $path_helper; + $this->extension_manager = $extension_manager; + $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/template/twig/environment.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index aa55f1e011..d71c02967c 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 0d0113e6da590c113068a60864d44372a2fbccab Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 15 Jun 2014 15:05:51 +0200 Subject: [ticket/12715] Cleanup comments in \phpbb\template\* PHPBB3-12715 --- phpBB/phpbb/template/twig/environment.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index d71c02967c..8d25153e14 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -40,7 +40,7 @@ class environment extends \Twig_Environment * @param \phpbb\path_helper * @param \phpbb\extension\manager * @param string $phpbb_root_path - * @param Twig_LoaderInterface $loader + * @param \Twig_LoaderInterface $loader * @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()) @@ -122,7 +122,7 @@ class environment extends \Twig_Environment * Set the namespace look up order to load templates from * * @param array $namespace - * @return Twig_Environment + * @return \Twig_Environment */ public function setNamespaceLookUpOrder($namespace) { @@ -132,12 +132,13 @@ class environment extends \Twig_Environment } /** - * Loads a template by name. - * - * @param string $name The template name - * @param integer $index The index if it is an embedded template - * @return Twig_TemplateInterface A template instance representing the given template name - */ + * Loads a template by name. + * + * @param string $name The template name + * @param integer $index The index if it is an embedded template + * @return \Twig_TemplateInterface A template instance representing the given template name + * @throws \Twig_Error_Loader + */ public function loadTemplate($name, $index = null) { if (strpos($name, '@') === false) @@ -168,11 +169,12 @@ class environment extends \Twig_Environment } /** - * Finds a template by name. - * - * @param string $name The template name - * @return string - */ + * Finds a template by name. + * + * @param string $name The template name + * @return string + * @throws \Twig_Error_Loader + */ public function findTemplate($name) { if (strpos($name, '@') === false) @@ -188,7 +190,7 @@ class environment extends \Twig_Environment return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name); } - catch (Twig_Error_Loader $e) + catch (\Twig_Error_Loader $e) { } } -- cgit v1.2.1 From dfcbace621b5cb28061828b94ed1ed2828a7d2e8 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 04:17:32 +0300 Subject: [ticket/12557] Template fixes PHPBB3-12557 --- phpBB/phpbb/template/twig/environment.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/template/twig/environment.php') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 8d25153e14..476ffd935e 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -36,11 +36,10 @@ class environment extends \Twig_Environment /** * Constructor * - * @param \phpbb\config\config $phpbb_config - * @param \phpbb\path_helper - * @param \phpbb\extension\manager - * @param string $phpbb_root_path - * @param \Twig_LoaderInterface $loader + * @param \phpbb\config\config $phpbb_config The phpBB configuration + * @param \phpbb\path_helper $path_helper phpBB path helper + * @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()) -- cgit v1.2.1