From a5bfc76a73a213a388126d0f697ba64f27a4b00d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 14 Sep 2014 21:18:20 +0200 Subject: [ticket/13063] Introduces a new \phpbb\routing\router class PHPBB3-13063 --- phpBB/phpbb/routing/router.php | 304 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 phpBB/phpbb/routing/router.php (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php new file mode 100644 index 0000000000..cebf19e702 --- /dev/null +++ b/phpBB/phpbb/routing/router.php @@ -0,0 +1,304 @@ + +* @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\routing; + +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\Generator\UrlGenerator; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Routing\Loader\YamlFileLoader; +use Symfony\Component\Config\FileLocator; +use phpbb\extension\manager; + +/** +* Integration of all pieces of the routing system for easier use. +*/ +class router implements RouterInterface +{ + /** + * @var manager Extension manager + */ + protected $extension_manager; + + /** + * @var string phpBB root path + */ + protected $phpbb_root_path; + + /** + * @var string PHP file extensions + */ + protected $php_ext; + + /** + * @var array YAML file(s) containing route information + */ + protected $routing_files; + + /** + * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null + */ + protected $matcher; + + /** + * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null + */ + protected $generator; + + /** + * @var RequestContext + */ + protected $context; + + /** + * @var RouteCollection|null + */ + protected $route_collection; + + /** + * Construct method + * + * @param manager $extension_manager The extension manager + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param array $routing_files Array of strings containing paths + * to YAML files holding route information + */ + public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $routing_files = array()) + { + $this->extension_manager = $extension_manager; + $this->routing_files = $routing_files; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->context = new RequestContext(); + } + + /** + * Find the list of routing files + * + * @param \phpbb\finder $finder + * @return router + */ + public function find_routing_files(\phpbb\finder $finder) + { + if ($this->routing_files === null || empty($this->routing_files)) + { + // We hardcode the path to the core config directory + // because the finder cannot find it + $this->routing_files = array_merge($this->routing_files, array('config/routing.yml'), array_keys($finder + ->directory('/config') + ->suffix('routing.yml') + ->find() + )); + } + + return $this; + } + + /** + * Find a list of controllers + * + * @param string $base_path Base path to prepend to file paths + * @return router + */ + public function find($base_path = '') + { + if ($this->route_collection === null || $this->route_collection->count() === 0) + { + $this->route_collection = new RouteCollection; + foreach ($this->routing_files as $file_path) + { + $loader = new YamlFileLoader(new FileLocator(phpbb_realpath($base_path))); + $this->route_collection->addCollection($loader->load($file_path)); + } + } + + return $this; + } + + /** + * Get the list of routes + * + * @return RouteCollection Get the route collection + */ + public function get_routes() + { + if ($this->route_collection == null || empty($this->routing_files)) + { + $this->find_routing_files($this->extension_manager->get_finder()) + ->find($this->phpbb_root_path); + } + + return $this->route_collection; + } + + /** + * {@inheritdoc} + */ + public function getRouteCollection() + { + return $this->get_routes(); + } + + /** + * {@inheritdoc} + */ + public function setContext(RequestContext $context) + { + $this->context = $context; + + if ($this->matcher !== null) + { + $this->get_matcher()->setContext($context); + } + if ($this->generator !== null) + { + $this->get_generator()->setContext($context); + } + } + + /** + * {@inheritdoc} + */ + public function getContext() + { + return $this->context; + } + + /** + * {@inheritdoc} + */ + public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) + { + return $this->get_generator()->generate($name, $parameters, $referenceType); + } + + /** + * {@inheritdoc} + */ + public function match($pathinfo) + { + return $this->get_matcher()->match($pathinfo); + } + + /** + * Gets the UrlMatcher instance associated with this Router. + * + * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface A UrlMatcherInterface instance + */ + public function get_matcher() + { + if ($this->matcher !== null) + { + return $this->matcher; + } + + if (defined('DEBUG')) + { + $this->create_new_url_matcher(); + } + else + { + $this->create_dumped_url_matcher(); + } + + return $this->matcher; + } + /** + * Creates a new dumped URL Matcher (dump it if necessary) + */ + protected function create_dumped_url_matcher() + { + if (!file_exists($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext)) + { + $dumper = new PhpMatcherDumper($this->get_routes()); + + $options = array( + 'class' => 'phpbb_url_matcher', + ); + + $dump = $dumper->dump($options); + file_put_contents($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext, $dump); + } + + require_once($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext); + + $this->matcher = new phpbb_url_matcher($this->context); + } + + /** + * Creates a new URL Matcher + */ + protected function create_new_url_matcher() + { + $this->matcher = new UrlMatcher($this->get_routes(), $this->context); + } + + /** + * Gets the UrlGenerator instance associated with this Router. + * + * @return \Symfony\Component\Routing\Generator\UrlGeneratorInterface A UrlGeneratorInterface instance + */ + public function get_generator() + { + if ($this->generator !== null) + { + return $this->generator; + } + + if (defined('DEBUG')) + { + $this->create_new_url_generator(); + } + else + { + $this->create_dumped_url_generator(); + } + + return $this->generator; + } + + /** + * Creates a new dumped URL Generator (dump it if necessary) + */ + protected function create_dumped_url_generator() + { + if (!file_exists($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext)) + { + $dumper = new PhpGeneratorDumper($this->get_routes()); + + $options = array( + 'class' => 'phpbb_url_generator', + ); + + $dump = $dumper->dump($options); + file_put_contents($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext, $dump); + } + + require_once($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext); + + $this->generator = new phpbb_url_generator($this->context); + } + + /** + * Creates a new URL Generator + */ + protected function create_new_url_generator() + { + $this->generator = new UrlGenerator($this->get_routes(), $this->context); + } +} -- cgit v1.2.1 From 2573dd18ca3327d0b5209a8d465f7911034c1302 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 20 Nov 2014 16:47:24 +0100 Subject: [ticket/13063] Fix coding style PHPBB3-13063 --- phpBB/phpbb/routing/router.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index cebf19e702..f721837bba 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -72,11 +72,10 @@ class router implements RouterInterface /** * Construct method * - * @param manager $extension_manager The extension manager - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param array $routing_files Array of strings containing paths - * to YAML files holding route information + * @param manager $extension_manager The extension manager + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param array $routing_files Array of strings containing paths to YAML files holding route information */ public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $routing_files = array()) { -- cgit v1.2.1 From 677b5b2cd4937ee6c777728082084c661223dee8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 20 Nov 2014 22:40:37 +0100 Subject: [ticket/12620] Fix rebase PHPBB3-12620 --- phpBB/phpbb/routing/router.php | 180 +++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 78 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index f721837bba..0617e94c93 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -25,95 +25,119 @@ use Symfony\Component\Config\FileLocator; use phpbb\extension\manager; /** -* Integration of all pieces of the routing system for easier use. -*/ + * Integration of all pieces of the routing system for easier use. + */ class router implements RouterInterface { /** - * @var manager Extension manager - */ + * Extension manager + * + * @var manager + */ protected $extension_manager; /** - * @var string phpBB root path - */ + * phpBB root path + * + * @var string + */ protected $phpbb_root_path; /** - * @var string PHP file extensions - */ + * PHP file extensions + * + * @var string + */ protected $php_ext; /** - * @var array YAML file(s) containing route information - */ + * Name of the current environment + * + * @var string + */ + protected $environment; + + /** + * YAML file(s) containing route information + * + * @var array + */ protected $routing_files; /** - * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null - */ + * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null + */ protected $matcher; /** - * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null - */ + * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|null + */ protected $generator; /** - * @var RequestContext - */ + * @var RequestContext + */ protected $context; /** - * @var RouteCollection|null - */ + * @var RouteCollection|null + */ protected $route_collection; /** - * Construct method - * - * @param manager $extension_manager The extension manager - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param array $routing_files Array of strings containing paths to YAML files holding route information - */ - public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $routing_files = array()) + * Construct method + * + * @param manager $extension_manager Extension manager + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param string $environment Name of the current environment + * @param array $routing_files Array of strings containing paths to YAML files holding route information + */ + public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array()) { $this->extension_manager = $extension_manager; $this->routing_files = $routing_files; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->environment = $environment; $this->context = new RequestContext(); } /** - * Find the list of routing files - * - * @param \phpbb\finder $finder - * @return router - */ - public function find_routing_files(\phpbb\finder $finder) + * Find the list of routing files + * + * @param array $paths Array of paths where to look for routing files. + * @return null + */ + public function find_routing_files(array $paths) { - if ($this->routing_files === null || empty($this->routing_files)) + $this->routing_files = array($this->phpbb_root_path . 'config/' . $this->environment . '/routing/environment.yml'); + foreach ($paths as $path) { - // We hardcode the path to the core config directory - // because the finder cannot find it - $this->routing_files = array_merge($this->routing_files, array('config/routing.yml'), array_keys($finder - ->directory('/config') - ->suffix('routing.yml') - ->find() - )); + if (file_exists($path . 'config/' . $this->environment . '/routing/environment.yml')) + { + $this->routing_files[] = $path . 'config/' . $this->environment . '/routing/environment.yml'; + } + else if (!is_dir($path . 'config/' . $this->environment)) + { + if (file_exists($path . 'config/default/routing/environment.yml')) + { + $this->routing_files[] = $path . 'config/default/routing/environment.yml'; + } + else if (!is_dir($path . 'config/default/routing') && file_exists($path . 'config/routing.yml')) + { + $this->routing_files[] = $path . 'config/routing.yml'; + } + } } - - return $this; } /** - * Find a list of controllers - * - * @param string $base_path Base path to prepend to file paths - * @return router - */ + * Find a list of controllers + * + * @param string $base_path Base path to prepend to file paths + * @return router + */ public function find($base_path = '') { if ($this->route_collection === null || $this->route_collection->count() === 0) @@ -130,15 +154,15 @@ class router implements RouterInterface } /** - * Get the list of routes - * - * @return RouteCollection Get the route collection - */ + * Get the list of routes + * + * @return RouteCollection Get the route collection + */ public function get_routes() { if ($this->route_collection == null || empty($this->routing_files)) { - $this->find_routing_files($this->extension_manager->get_finder()) + $this->find_routing_files($this->extension_manager->all_enabled()) ->find($this->phpbb_root_path); } @@ -146,16 +170,16 @@ class router implements RouterInterface } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function getRouteCollection() { return $this->get_routes(); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function setContext(RequestContext $context) { $this->context = $context; @@ -171,34 +195,34 @@ class router implements RouterInterface } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function getContext() { return $this->context; } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { return $this->get_generator()->generate($name, $parameters, $referenceType); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function match($pathinfo) { return $this->get_matcher()->match($pathinfo); } /** - * Gets the UrlMatcher instance associated with this Router. - * - * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface A UrlMatcherInterface instance - */ + * Gets the UrlMatcher instance associated with this Router. + * + * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface A UrlMatcherInterface instance + */ public function get_matcher() { if ($this->matcher !== null) @@ -218,8 +242,8 @@ class router implements RouterInterface return $this->matcher; } /** - * Creates a new dumped URL Matcher (dump it if necessary) - */ + * Creates a new dumped URL Matcher (dump it if necessary) + */ protected function create_dumped_url_matcher() { if (!file_exists($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext)) @@ -240,18 +264,18 @@ class router implements RouterInterface } /** - * Creates a new URL Matcher - */ + * Creates a new URL Matcher + */ protected function create_new_url_matcher() { $this->matcher = new UrlMatcher($this->get_routes(), $this->context); } /** - * Gets the UrlGenerator instance associated with this Router. - * - * @return \Symfony\Component\Routing\Generator\UrlGeneratorInterface A UrlGeneratorInterface instance - */ + * Gets the UrlGenerator instance associated with this Router. + * + * @return \Symfony\Component\Routing\Generator\UrlGeneratorInterface A UrlGeneratorInterface instance + */ public function get_generator() { if ($this->generator !== null) @@ -272,8 +296,8 @@ class router implements RouterInterface } /** - * Creates a new dumped URL Generator (dump it if necessary) - */ + * Creates a new dumped URL Generator (dump it if necessary) + */ protected function create_dumped_url_generator() { if (!file_exists($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext)) @@ -294,8 +318,8 @@ class router implements RouterInterface } /** - * Creates a new URL Generator - */ + * Creates a new URL Generator + */ protected function create_new_url_generator() { $this->generator = new UrlGenerator($this->get_routes(), $this->context); -- cgit v1.2.1 From f5c5f7df755dd930fef4de6f62e42d4a2a54219e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 21 Nov 2014 08:26:19 +0100 Subject: [ticket/12620] Fix functionnal tests PHPBB3-12620 --- phpBB/phpbb/routing/router.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 0617e94c93..1003708540 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -107,7 +107,7 @@ class router implements RouterInterface * Find the list of routing files * * @param array $paths Array of paths where to look for routing files. - * @return null + * @return router */ public function find_routing_files(array $paths) { @@ -130,6 +130,8 @@ class router implements RouterInterface } } } + + return $this; } /** -- cgit v1.2.1 From fd94027b40184b4c9eae10c6e5c1f8bee2c2a974 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Nov 2014 12:23:16 +0100 Subject: [ticket/13372] Fix Url Generator/Matcher generation PHPBB3-13372 --- phpBB/phpbb/routing/router.php | 45 ++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 1003708540..c9c50534a2 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -13,6 +13,7 @@ namespace phpbb\routing; +use Symfony\Component\Config\ConfigCache; use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\Matcher\UrlMatcher; @@ -232,14 +233,7 @@ class router implements RouterInterface return $this->matcher; } - if (defined('DEBUG')) - { - $this->create_new_url_matcher(); - } - else - { - $this->create_dumped_url_matcher(); - } + $this->create_dumped_url_matcher(); return $this->matcher; } @@ -248,21 +242,22 @@ class router implements RouterInterface */ protected function create_dumped_url_matcher() { - if (!file_exists($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext)) + $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG')); + if (!$cache->isFresh()) { $dumper = new PhpMatcherDumper($this->get_routes()); $options = array( - 'class' => 'phpbb_url_matcher', + 'class' => 'phpbb_url_matcher', + 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', ); - $dump = $dumper->dump($options); - file_put_contents($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext, $dump); + $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once($this->phpbb_root_path . 'cache/url_matcher.' . $this->php_ext); + require_once $cache; - $this->matcher = new phpbb_url_matcher($this->context); + $this->matcher = new \phpbb_url_matcher($this->context); } /** @@ -285,14 +280,7 @@ class router implements RouterInterface return $this->generator; } - if (defined('DEBUG')) - { - $this->create_new_url_generator(); - } - else - { - $this->create_dumped_url_generator(); - } + $this->create_dumped_url_generator(); return $this->generator; } @@ -302,21 +290,22 @@ class router implements RouterInterface */ protected function create_dumped_url_generator() { - if (!file_exists($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext)) + $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); + if (!$cache->isFresh()) { $dumper = new PhpGeneratorDumper($this->get_routes()); $options = array( - 'class' => 'phpbb_url_generator', + 'class' => 'phpbb_url_generator', + 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', ); - $dump = $dumper->dump($options); - file_put_contents($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext, $dump); + $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once($this->phpbb_root_path . 'cache/url_generator.' . $this->php_ext); + require_once $cache; - $this->generator = new phpbb_url_generator($this->context); + $this->generator = new \phpbb_url_generator($this->context); } /** -- cgit v1.2.1 From f4576c969ab3c3619564e8be7b71547049846bd5 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Nov 2014 12:48:48 +0100 Subject: [ticket/13372] Fix require_once CS PHPBB3-13372 --- phpBB/phpbb/routing/router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index c9c50534a2..40a829b73f 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -255,7 +255,7 @@ class router implements RouterInterface $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once $cache; + require_once($cache); $this->matcher = new \phpbb_url_matcher($this->context); } @@ -303,7 +303,7 @@ class router implements RouterInterface $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once $cache; + require_once($cache); $this->generator = new \phpbb_url_generator($this->context); } -- cgit v1.2.1 From 6842831d6baa59425ec83cc2ebbae377942824ce Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 17 Jan 2015 11:05:18 +0100 Subject: [ticket/13513] Use paths relative to the phpBB root in the router PHPBB3-13513 --- phpBB/phpbb/routing/router.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 1003708540..601d774129 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -106,25 +106,25 @@ class router implements RouterInterface /** * Find the list of routing files * - * @param array $paths Array of paths where to look for routing files. + * @param array $paths Array of paths where to look for routing files (they must be relative to the phpBB root path). * @return router */ public function find_routing_files(array $paths) { - $this->routing_files = array($this->phpbb_root_path . 'config/' . $this->environment . '/routing/environment.yml'); + $this->routing_files = array('config/' . $this->environment . '/routing/environment.yml'); foreach ($paths as $path) { - if (file_exists($path . 'config/' . $this->environment . '/routing/environment.yml')) + if (file_exists($this->phpbb_root_path . $path . 'config/' . $this->environment . '/routing/environment.yml')) { $this->routing_files[] = $path . 'config/' . $this->environment . '/routing/environment.yml'; } - else if (!is_dir($path . 'config/' . $this->environment)) + else if (!is_dir($this->phpbb_root_path . $path . 'config/' . $this->environment)) { - if (file_exists($path . 'config/default/routing/environment.yml')) + if (file_exists($this->phpbb_root_path . $path . 'config/default/routing/environment.yml')) { $this->routing_files[] = $path . 'config/default/routing/environment.yml'; } - else if (!is_dir($path . 'config/default/routing') && file_exists($path . 'config/routing.yml')) + else if (!is_dir($this->phpbb_root_path . $path . 'config/default/routing') && file_exists($this->phpbb_root_path . $path . 'config/routing.yml')) { $this->routing_files[] = $path . 'config/routing.yml'; } @@ -164,7 +164,7 @@ class router implements RouterInterface { if ($this->route_collection == null || empty($this->routing_files)) { - $this->find_routing_files($this->extension_manager->all_enabled()) + $this->find_routing_files($this->extension_manager->all_enabled(false)) ->find($this->phpbb_root_path); } -- cgit v1.2.1 From 4bdef6fd21a5dcab455b0cd1ee2652de606929c3 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 12 Mar 2015 00:25:00 +0100 Subject: [ticket/13697] Moving filesystem related functions to filesystem service * Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697 --- phpBB/phpbb/routing/router.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 4ccd3cf5e3..5313106b0a 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -85,17 +85,24 @@ class router implements RouterInterface */ protected $route_collection; + /** + * @var \phpbb\filesystem\filesystem_interface + */ + protected $filesystem; + /** * Construct method * + * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem helper * @param manager $extension_manager Extension manager * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP file extension * @param string $environment Name of the current environment * @param array $routing_files Array of strings containing paths to YAML files holding route information */ - public function __construct(manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array()) + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array()) { + $this->filesystem = $filesystem; $this->extension_manager = $extension_manager; $this->routing_files = $routing_files; $this->phpbb_root_path = $phpbb_root_path; @@ -148,7 +155,7 @@ class router implements RouterInterface $this->route_collection = new RouteCollection; foreach ($this->routing_files as $file_path) { - $loader = new YamlFileLoader(new FileLocator(phpbb_realpath($base_path))); + $loader = new YamlFileLoader(new FileLocator($this->filesystem->realpath($base_path))); $this->route_collection->addCollection($loader->load($file_path)); } } -- cgit v1.2.1 From de5a5c41f8e8e47d0740fa97d3d83d57168b18b4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 19 Apr 2015 17:41:29 +0200 Subject: [ticket/13768] Fix deprecations PHPBB3-13768 --- phpBB/phpbb/routing/router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 5313106b0a..7444f06253 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -262,7 +262,7 @@ class router implements RouterInterface $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once($cache); + require_once($cache->getPath()); $this->matcher = new \phpbb_url_matcher($this->context); } @@ -310,7 +310,7 @@ class router implements RouterInterface $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } - require_once($cache); + require_once($cache->getPath()); $this->generator = new \phpbb_url_generator($this->context); } -- cgit v1.2.1 From 74dbaac0394f45955553ff46515404fe5b06bfba Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 30 Apr 2015 22:40:17 +0200 Subject: [ticket/13800] Make router's extension manager dependency optional PHPBB3-13800 --- phpBB/phpbb/routing/router.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 7444f06253..dd5bffe22b 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -94,13 +94,14 @@ class router implements RouterInterface * Construct method * * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem helper - * @param manager $extension_manager Extension manager - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param string $environment Name of the current environment - * @param array $routing_files Array of strings containing paths to YAML files holding route information + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param string $environment Name of the current environment + * @param manager|null $extension_manager Extension manager + * @param array $routing_files Array of strings containing paths to YAML files + * holding route information */ - public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, manager $extension_manager, $phpbb_root_path, $php_ext, $environment, $routing_files = array()) + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $environment, manager $extension_manager = null, $routing_files = array()) { $this->filesystem = $filesystem; $this->extension_manager = $extension_manager; @@ -172,7 +173,9 @@ class router implements RouterInterface { if ($this->route_collection == null || empty($this->routing_files)) { - $this->find_routing_files($this->extension_manager->all_enabled(false)) + $this->find_routing_files( + ($this->extension_manager !== null) ? $this->extension_manager->all_enabled(false) : array() + ) ->find($this->phpbb_root_path); } -- cgit v1.2.1 From d48e95bb3a17f111e9d4d8111630be44ef9019e4 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 10 May 2015 19:18:10 +0200 Subject: [ticket/13829] Don't fail if the cache isn't writeable PHPBB3-13829 --- phpBB/phpbb/routing/router.php | 59 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 7444f06253..f74760fa13 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -14,6 +14,7 @@ namespace phpbb\routing; use Symfony\Component\Config\ConfigCache; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\Matcher\UrlMatcher; @@ -249,22 +250,29 @@ class router implements RouterInterface */ protected function create_dumped_url_matcher() { - $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG')); - if (!$cache->isFresh()) + try { - $dumper = new PhpMatcherDumper($this->get_routes()); + $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG')); + if (!$cache->isFresh()) + { + $dumper = new PhpMatcherDumper($this->get_routes()); - $options = array( - 'class' => 'phpbb_url_matcher', - 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', - ); + $options = array( + 'class' => 'phpbb_url_matcher', + 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', + ); - $cache->write($dumper->dump($options), $this->get_routes()->getResources()); - } + $cache->write($dumper->dump($options), $this->get_routes()->getResources()); + } - require_once($cache->getPath()); + require_once($cache->getPath()); - $this->matcher = new \phpbb_url_matcher($this->context); + $this->matcher = new \phpbb_url_matcher($this->context); + } + catch (IOException $e) + { + $this->create_new_url_matcher(); + } } /** @@ -297,22 +305,29 @@ class router implements RouterInterface */ protected function create_dumped_url_generator() { - $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); - if (!$cache->isFresh()) + try { - $dumper = new PhpGeneratorDumper($this->get_routes()); + $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); + if (!$cache->isFresh()) + { + $dumper = new PhpGeneratorDumper($this->get_routes()); - $options = array( - 'class' => 'phpbb_url_generator', - 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', - ); + $options = array( + 'class' => 'phpbb_url_generator', + 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', + ); - $cache->write($dumper->dump($options), $this->get_routes()->getResources()); - } + $cache->write($dumper->dump($options), $this->get_routes()->getResources()); + } - require_once($cache->getPath()); + require_once($cache->getPath()); - $this->generator = new \phpbb_url_generator($this->context); + $this->generator = new \phpbb_url_generator($this->context); + } + catch (IOException $e) + { + $this->create_new_url_generator(); + } } /** -- cgit v1.2.1 From 66c0e0c6a83fbf091aa078ab06dd6467c8c6aa11 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 4 May 2015 15:10:33 +0200 Subject: [ticket/13388] Integrate routing and di parameters resolution PHPBB3-13388 --- phpBB/phpbb/routing/router.php | 130 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 2f89d4e884..ca9799ba3e 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -15,6 +15,9 @@ namespace phpbb\routing; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Filesystem\Exception\IOException; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\Matcher\UrlMatcher; @@ -91,18 +94,23 @@ class router implements RouterInterface */ protected $filesystem; + /** + * @var ContainerInterface + */ + protected $container; + /** * Construct method * + * @param ContainerInterface $container DI container * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem helper - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param string $environment Name of the current environment - * @param manager|null $extension_manager Extension manager - * @param array $routing_files Array of strings containing paths to YAML files - * holding route information + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param string $environment Name of the current environment + * @param manager $extension_manager Extension manager + * @param array $routing_files Array of strings containing paths to YAML files holding route information */ - public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $environment, manager $extension_manager = null, $routing_files = array()) + public function __construct(ContainerInterface $container, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $environment, manager $extension_manager = null, $routing_files = array()) { $this->filesystem = $filesystem; $this->extension_manager = $extension_manager; @@ -162,9 +170,117 @@ class router implements RouterInterface } } + $this->resolveParameters($this->route_collection); + return $this; } + /** + * Replaces placeholders with service container parameter values in: + * - the route defaults, + * - the route requirements, + * - the route path, + * - the route host, + * - the route schemes, + * - the route methods. + * + * @param RouteCollection $collection + */ + private function resolveParameters(RouteCollection $collection) + { + foreach ($collection as $route) + { + foreach ($route->getDefaults() as $name => $value) + { + $route->setDefault($name, $this->resolve($value)); + } + + foreach ($route->getRequirements() as $name => $value) + { + if ($name === '_scheme' || $name === '_method') + { + continue; // ignore deprecated requirements to not trigger deprecation warnings + } + + $route->setRequirement($name, $this->resolve($value)); + } + + $route->setPath($this->resolve($route->getPath())); + $route->setHost($this->resolve($route->getHost())); + + $schemes = array(); + foreach ($route->getSchemes() as $scheme) + { + $schemes = array_merge($schemes, explode('|', $this->resolve($scheme))); + } + + $route->setSchemes($schemes); + $methods = array(); + foreach ($route->getMethods() as $method) + { + $methods = array_merge($methods, explode('|', $this->resolve($method))); + } + + $route->setMethods($methods); + $route->setCondition($this->resolve($route->getCondition())); + } + } + /** + * Recursively replaces placeholders with the service container parameters. + * + * @param mixed $value The source which might contain "%placeholders%" + * + * @return mixed The source with the placeholders replaced by the container + * parameters. Arrays are resolved recursively. + * + * @throws ParameterNotFoundException When a placeholder does not exist as a container parameter + * @throws RuntimeException When a container value is not a string or a numeric value + */ + private function resolve($value) + { + if (is_array($value)) + { + foreach ($value as $key => $val) + { + $value[$key] = $this->resolve($val); + } + + return $value; + } + + if (!is_string($value)) + { + return $value; + } + + $container = $this->container; + $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) + { + // skip %% + if (!isset($match[1])) + { + return '%%'; + } + + $resolved = $container->getParameter($match[1]); + if (is_string($resolved) || is_numeric($resolved)) + { + return (string) $resolved; + } + + throw new RuntimeException(sprintf( + 'The container parameter "%s", used in the route configuration value "%s", '. + 'must be a string or numeric, but it is of type %s.', + $match[1], + $value, + gettype($resolved) + ) + ); + }, $value); + + return str_replace('%%', '%', $escapedValue); + } + /** * Get the list of routes * -- cgit v1.2.1 From 6656567424843d7118aba1eeb5fc0f4eb61a2e5a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 29 May 2015 16:37:58 +0200 Subject: [ticket/13388] Address comments PHPBB3-13388 --- phpBB/phpbb/routing/router.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index ca9799ba3e..270b54c4ba 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -195,13 +195,12 @@ class router implements RouterInterface $route->setDefault($name, $this->resolve($value)); } + $requirements = $route->getRequirements(); + unset($requirements['_scheme']); + unset($requirements['_method']); + foreach ($route->getRequirements() as $name => $value) { - if ($name === '_scheme' || $name === '_method') - { - continue; // ignore deprecated requirements to not trigger deprecation warnings - } - $route->setRequirement($name, $this->resolve($value)); } -- cgit v1.2.1 From 80375c98f0f39a957b3348c9384fdc52ba27ea36 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 29 May 2015 16:52:21 +0200 Subject: [ticket/13388] Fix rebase PHPBB3-13388 --- phpBB/phpbb/routing/router.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 270b54c4ba..1c27e95e4d 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -112,6 +112,7 @@ class router implements RouterInterface */ public function __construct(ContainerInterface $container, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $environment, manager $extension_manager = null, $routing_files = array()) { + $this->container = $container; $this->filesystem = $filesystem; $this->extension_manager = $extension_manager; $this->routing_files = $routing_files; -- cgit v1.2.1 From d129ee6c947c6bf494166c47b2d04c7d66e41ab4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 29 May 2015 16:53:54 +0200 Subject: [ticket/13388] Fix deprecations PHPBB3-13388 --- phpBB/phpbb/routing/router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 1c27e95e4d..75726011c4 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -200,7 +200,7 @@ class router implements RouterInterface unset($requirements['_scheme']); unset($requirements['_method']); - foreach ($route->getRequirements() as $name => $value) + foreach ($requirements as $name => $value) { $route->setRequirement($name, $this->resolve($value)); } -- cgit v1.2.1 From ea7114e78528f95fae077568573f2b3363f9aab1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 30 May 2015 13:14:27 +0200 Subject: [ticket/13388] Fix coding style PHPBB3-13388 --- phpBB/phpbb/routing/router.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 75726011c4..5af005769f 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -225,6 +225,7 @@ class router implements RouterInterface $route->setCondition($this->resolve($route->getCondition())); } } + /** * Recursively replaces placeholders with the service container parameters. * -- cgit v1.2.1 From 8e5e954438b232f4ce7aec6a5db3d52b974c07a8 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 22 Feb 2015 23:36:27 +0100 Subject: [ticket/13645] Move the feeds to controllers PHPBB3-13645 --- phpBB/phpbb/routing/helper.php | 153 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 phpBB/phpbb/routing/helper.php (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/helper.php b/phpBB/phpbb/routing/helper.php new file mode 100644 index 0000000000..f56974a354 --- /dev/null +++ b/phpBB/phpbb/routing/helper.php @@ -0,0 +1,153 @@ + +* @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\routing; + +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RequestContext; + +/** +* Controller helper class, contains methods that do things for controllers +*/ +class helper +{ + /** + * config object + * @var \phpbb\config\config + */ + protected $config; + + /** + * phpBB router + * @var \phpbb\routing\router + */ + protected $router; + + /** + * @var \phpbb\symfony_request + */ + protected $symfony_request; + + /** + * @var \phpbb\request\request_interface + */ + protected $request; + + /** + * @var \phpbb\filesystem The filesystem object + */ + protected $filesystem; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param \phpbb\config\config $config Config object + * @param \phpbb\routing\router $router phpBB router + * @param \phpbb\symfony_request $symfony_request Symfony Request object + * @param \phpbb\request\request_interface $request phpBB request object + * @param \phpbb\filesystem\filesystem $filesystem The filesystem object + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + */ + public function __construct(\phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem $filesystem, $phpbb_root_path, $php_ext) + { + $this->config = $config; + $this->router = $router; + $this->symfony_request = $symfony_request; + $this->request = $request; + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Generate a URL to a route + * + * @param string $route Name of the route to travel + * @param array $params String or array of additional url parameters + * @param bool $is_amp Is url using & (true) or & (false) + * @param string|bool $session_id Possibility to use a custom session id instead of the global one + * @param bool|string $reference_type The type of reference to be generated (one of the constants) + * @return string The URL already passed through append_sid() + */ + public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) + { + $anchor = ''; + if (isset($params['#'])) + { + $anchor = '#' . $params['#']; + unset($params['#']); + } + + $context = new RequestContext(); + $context->fromRequest($this->symfony_request); + + $script_name = $this->symfony_request->getScriptName(); + $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); + + $base_url = $context->getBaseUrl(); + + // Append page name if base URL does not contain it + if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) + { + $base_url .= '/' . $page_name; + } + + // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it. + $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); + + // We need to update the base url to move to the directory of the app.php file if the current script is not app.php + if ($page_name !== 'app.php') + { + if (empty($this->config['enable_mod_rewrite'])) + { + $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url); + } + else + { + $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path); + } + } + + $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true); + + $context->setBaseUrl($base_url); + + $this->router->setContext($context); + $route_url = $this->router->generate($route, $params, $reference_type); + + if ($is_amp) + { + $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); + } + + if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) + { + $route_url = 'app.' . $this->php_ext . '/' . $route_url; + } + + return append_sid($route_url . $anchor, false, $is_amp, $session_id, true); + } +} -- cgit v1.2.1 From 403c647b9e84640977ca0f98d21d15ceb4957bdb Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 7 Oct 2015 23:09:13 +0200 Subject: [ticket/14220] Move route loading to services PHPBB3-14220 --- phpBB/phpbb/routing/file_locator.php | 33 ++ phpBB/phpbb/routing/loader_resolver.php | 49 +++ .../chained_resources_locator.php | 47 +++ .../default_resources_locator.php | 105 +++++++ .../resources_locator_interface.php | 27 ++ phpBB/phpbb/routing/router.php | 346 +++++++++------------ 6 files changed, 407 insertions(+), 200 deletions(-) create mode 100644 phpBB/phpbb/routing/file_locator.php create mode 100644 phpBB/phpbb/routing/loader_resolver.php create mode 100644 phpBB/phpbb/routing/resources_locator/chained_resources_locator.php create mode 100644 phpBB/phpbb/routing/resources_locator/default_resources_locator.php create mode 100644 phpBB/phpbb/routing/resources_locator/resources_locator_interface.php (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/file_locator.php b/phpBB/phpbb/routing/file_locator.php new file mode 100644 index 0000000000..64efcc6c76 --- /dev/null +++ b/phpBB/phpbb/routing/file_locator.php @@ -0,0 +1,33 @@ + +* @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\routing; + +use phpbb\filesystem\filesystem_interface; +use Symfony\Component\Config\FileLocator; + +class file_locator extends FileLocator +{ + public function __construct(filesystem_interface $filesystem, $paths = []) + { + $paths = (array) $paths; + $absolute_paths = []; + + foreach ($paths as $path) + { + $absolute_paths[] = $filesystem->realpath($path); + } + + parent::__construct($absolute_paths); + } +} diff --git a/phpBB/phpbb/routing/loader_resolver.php b/phpBB/phpbb/routing/loader_resolver.php new file mode 100644 index 0000000000..e335051444 --- /dev/null +++ b/phpBB/phpbb/routing/loader_resolver.php @@ -0,0 +1,49 @@ + +* @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\routing; + +use Symfony\Component\Config\Loader\LoaderResolverInterface; + +/** + * @see Symfony\Component\Config\Loader\LoaderResolver + */ +class loader_resolver implements LoaderResolverInterface +{ + /** + * @var \Symfony\Component\Config\Loader\LoaderInterface[] An array of LoaderInterface objects + */ + protected $loaders = []; + + public function __construct($loaders = []) + { + $this->loaders = $loaders; + } + + /** + * {@inheritdoc} + */ + public function resolve($resource, $type = null) + { + /** @var \Symfony\Component\Config\Loader\LoaderInterface $loader */ + foreach ($this->loaders as $loader) + { + if ($loader->supports($resource, $type)) + { + return $loader; + } + } + + return false; + } +} diff --git a/phpBB/phpbb/routing/resources_locator/chained_resources_locator.php b/phpBB/phpbb/routing/resources_locator/chained_resources_locator.php new file mode 100644 index 0000000000..db9abf2095 --- /dev/null +++ b/phpBB/phpbb/routing/resources_locator/chained_resources_locator.php @@ -0,0 +1,47 @@ + +* @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\routing\resources_locator; + +class chained_resources_locator implements resources_locator_interface +{ + /** + * @var resources_locator_interface[] + */ + protected $locators; + + /** + * Construct method + * + * @param resources_locator_interface[] $locators Locators + */ + public function __construct($locators) + { + $this->locators = $locators; + } + + /** + * {@inheritdoc} + */ + public function locate_resources() + { + $resources = []; + + foreach ($this->locators as $locator) + { + $resources = array_merge($resources, $locator->locate_resources()); + } + + return $resources; + } +} diff --git a/phpBB/phpbb/routing/resources_locator/default_resources_locator.php b/phpBB/phpbb/routing/resources_locator/default_resources_locator.php new file mode 100644 index 0000000000..90c3877007 --- /dev/null +++ b/phpBB/phpbb/routing/resources_locator/default_resources_locator.php @@ -0,0 +1,105 @@ + +* @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\routing\resources_locator; + +use phpbb\extension\manager; + +/** + * Locates the yaml routing resources located in the default locations + */ +class default_resources_locator implements resources_locator_interface +{ + /** + * phpBB root path + * + * @var string + */ + protected $phpbb_root_path; + + /** + * Name of the current environment + * + * @var string + */ + protected $environment; + + /** + * Extension manager + * + * @var manager + */ + protected $extension_manager; + + /** + * Construct method + * + * @param string $phpbb_root_path phpBB root path + * @param string $environment Name of the current environment + * @param manager $extension_manager Extension manager + */ + public function __construct($phpbb_root_path, $environment, manager $extension_manager = null) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->environment = $environment; + $this->extension_manager = $extension_manager; + } + + /** + * {@inheritdoc} + */ + public function locate_resources() + { + $resources = [['config/' . $this->environment . '/routing/environment.yml', 'yaml']]; + + $resources = $this->append_ext_resources($resources); + + return $resources; + } + + /** + * Append extension resources to an array of resouces + * + * @see resources_locator_interface::locate_resources() + * + * @param mixed[] $resources List of resources + * + * @return mixed[] List of resources + */ + protected function append_ext_resources(array $resources) + { + if ($this->extension_manager !== null) + { + foreach ($this->extension_manager->all_enabled(false) as $path) + { + if (file_exists($this->phpbb_root_path . $path . 'config/' . $this->environment . '/routing/environment.yml')) + { + $resources[] = [$path . 'config/' . $this->environment . '/routing/environment.yml', 'yaml']; + } + else if (!is_dir($this->phpbb_root_path . $path . 'config/' . $this->environment)) + { + if (file_exists($this->phpbb_root_path . $path . 'config/default/routing/environment.yml')) + { + $resources[] = [$path . 'config/default/routing/environment.yml', 'yaml']; + } + else if (!is_dir($this->phpbb_root_path . $path . 'config/default/routing') && file_exists($this->phpbb_root_path . $path . 'config/routing.yml')) + { + $resources[] = [$path . 'config/routing.yml', 'yaml']; + } + } + } + } + + return $resources; + } +} diff --git a/phpBB/phpbb/routing/resources_locator/resources_locator_interface.php b/phpBB/phpbb/routing/resources_locator/resources_locator_interface.php new file mode 100644 index 0000000000..46335cb288 --- /dev/null +++ b/phpBB/phpbb/routing/resources_locator/resources_locator_interface.php @@ -0,0 +1,27 @@ + + * @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\routing\resources_locator; + +interface resources_locator_interface +{ + /** + * Locates a list of resources used to load the routes + * + * Each entry of the list can be either the resource or an array composed of 2 elements: + * the resource and its type. + * + * @return mixed[] List of resources + */ + public function locate_resources(); +} diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 5af005769f..5d237b6433 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -13,21 +13,20 @@ namespace phpbb\routing; +use phpbb\routing\resources_locator\resources_locator_interface; use Symfony\Component\Config\ConfigCache; -use Symfony\Component\Filesystem\Exception\IOException; +use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; -use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; -use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Generator\UrlGenerator; +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\Routing\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; -use phpbb\extension\manager; /** * Integration of all pieces of the routing system for easier use. @@ -35,11 +34,19 @@ use phpbb\extension\manager; class router implements RouterInterface { /** - * Extension manager - * - * @var manager + * @var ContainerInterface */ - protected $extension_manager; + protected $container; + + /** + * @var resources_locator_interface + */ + protected $resources_locator; + + /** + * @var LoaderInterface + */ + protected $loader; /** * phpBB root path @@ -62,13 +69,6 @@ class router implements RouterInterface */ protected $environment; - /** - * YAML file(s) containing route information - * - * @var array - */ - protected $routing_files; - /** * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null */ @@ -85,37 +85,25 @@ class router implements RouterInterface protected $context; /** - * @var RouteCollection|null + * @var RouteCollection */ protected $route_collection; - /** - * @var \phpbb\filesystem\filesystem_interface - */ - protected $filesystem; - - /** - * @var ContainerInterface - */ - protected $container; - /** * Construct method * - * @param ContainerInterface $container DI container - * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem helper - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension - * @param string $environment Name of the current environment - * @param manager $extension_manager Extension manager - * @param array $routing_files Array of strings containing paths to YAML files holding route information + * @param ContainerInterface $container DI container + * @param resources_locator_interface $resources_locator Resources locator + * @param LoaderInterface $loader Resources loader + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + * @param string $environment Name of the current environment */ - public function __construct(ContainerInterface $container, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $environment, manager $extension_manager = null, $routing_files = array()) + public function __construct(ContainerInterface $container, resources_locator_interface $resources_locator, LoaderInterface $loader, $phpbb_root_path, $php_ext, $environment) { $this->container = $container; - $this->filesystem = $filesystem; - $this->extension_manager = $extension_manager; - $this->routing_files = $routing_files; + $this->resources_locator = $resources_locator; + $this->loader = $loader; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->environment = $environment; @@ -123,178 +111,28 @@ class router implements RouterInterface } /** - * Find the list of routing files + * Get the list of routes * - * @param array $paths Array of paths where to look for routing files (they must be relative to the phpBB root path). - * @return router + * @return RouteCollection Get the route collection */ - public function find_routing_files(array $paths) + public function get_routes() { - $this->routing_files = array('config/' . $this->environment . '/routing/environment.yml'); - foreach ($paths as $path) + if ($this->route_collection === null /*|| $this->route_collection->count() === 0*/) { - if (file_exists($this->phpbb_root_path . $path . 'config/' . $this->environment . '/routing/environment.yml')) - { - $this->routing_files[] = $path . 'config/' . $this->environment . '/routing/environment.yml'; - } - else if (!is_dir($this->phpbb_root_path . $path . 'config/' . $this->environment)) + $this->route_collection = new RouteCollection; + foreach ($this->resources_locator->locate_resources() as $resource) { - if (file_exists($this->phpbb_root_path . $path . 'config/default/routing/environment.yml')) + if (is_array($resource)) { - $this->routing_files[] = $path . 'config/default/routing/environment.yml'; + $this->route_collection->addCollection($this->loader->load($resource[0], $resource[1])); } - else if (!is_dir($this->phpbb_root_path . $path . 'config/default/routing') && file_exists($this->phpbb_root_path . $path . 'config/routing.yml')) + else { - $this->routing_files[] = $path . 'config/routing.yml'; + $this->route_collection->addCollection($this->loader->load($resource)); } } - } - return $this; - } - - /** - * Find a list of controllers - * - * @param string $base_path Base path to prepend to file paths - * @return router - */ - public function find($base_path = '') - { - if ($this->route_collection === null || $this->route_collection->count() === 0) - { - $this->route_collection = new RouteCollection; - foreach ($this->routing_files as $file_path) - { - $loader = new YamlFileLoader(new FileLocator($this->filesystem->realpath($base_path))); - $this->route_collection->addCollection($loader->load($file_path)); - } - } - - $this->resolveParameters($this->route_collection); - - return $this; - } - - /** - * Replaces placeholders with service container parameter values in: - * - the route defaults, - * - the route requirements, - * - the route path, - * - the route host, - * - the route schemes, - * - the route methods. - * - * @param RouteCollection $collection - */ - private function resolveParameters(RouteCollection $collection) - { - foreach ($collection as $route) - { - foreach ($route->getDefaults() as $name => $value) - { - $route->setDefault($name, $this->resolve($value)); - } - - $requirements = $route->getRequirements(); - unset($requirements['_scheme']); - unset($requirements['_method']); - - foreach ($requirements as $name => $value) - { - $route->setRequirement($name, $this->resolve($value)); - } - - $route->setPath($this->resolve($route->getPath())); - $route->setHost($this->resolve($route->getHost())); - - $schemes = array(); - foreach ($route->getSchemes() as $scheme) - { - $schemes = array_merge($schemes, explode('|', $this->resolve($scheme))); - } - - $route->setSchemes($schemes); - $methods = array(); - foreach ($route->getMethods() as $method) - { - $methods = array_merge($methods, explode('|', $this->resolve($method))); - } - - $route->setMethods($methods); - $route->setCondition($this->resolve($route->getCondition())); - } - } - - /** - * Recursively replaces placeholders with the service container parameters. - * - * @param mixed $value The source which might contain "%placeholders%" - * - * @return mixed The source with the placeholders replaced by the container - * parameters. Arrays are resolved recursively. - * - * @throws ParameterNotFoundException When a placeholder does not exist as a container parameter - * @throws RuntimeException When a container value is not a string or a numeric value - */ - private function resolve($value) - { - if (is_array($value)) - { - foreach ($value as $key => $val) - { - $value[$key] = $this->resolve($val); - } - - return $value; - } - - if (!is_string($value)) - { - return $value; - } - - $container = $this->container; - $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) - { - // skip %% - if (!isset($match[1])) - { - return '%%'; - } - - $resolved = $container->getParameter($match[1]); - if (is_string($resolved) || is_numeric($resolved)) - { - return (string) $resolved; - } - - throw new RuntimeException(sprintf( - 'The container parameter "%s", used in the route configuration value "%s", '. - 'must be a string or numeric, but it is of type %s.', - $match[1], - $value, - gettype($resolved) - ) - ); - }, $value); - - return str_replace('%%', '%', $escapedValue); - } - - /** - * Get the list of routes - * - * @return RouteCollection Get the route collection - */ - public function get_routes() - { - if ($this->route_collection == null || empty($this->routing_files)) - { - $this->find_routing_files( - ($this->extension_manager !== null) ? $this->extension_manager->all_enabled(false) : array() - ) - ->find($this->phpbb_root_path); + $this->resolveParameters($this->route_collection); } return $this->route_collection; @@ -365,6 +203,7 @@ class router implements RouterInterface return $this->matcher; } + /** * Creates a new dumped URL Matcher (dump it if necessary) */ @@ -457,4 +296,111 @@ class router implements RouterInterface { $this->generator = new UrlGenerator($this->get_routes(), $this->context); } + + /** + * Replaces placeholders with service container parameter values in: + * - the route defaults, + * - the route requirements, + * - the route path, + * - the route host, + * - the route schemes, + * - the route methods. + * + * @param RouteCollection $collection + */ + protected function resolveParameters(RouteCollection $collection) + { + /** @var \Symfony\Component\Routing\Route $route */ + foreach ($collection as $route) + { + foreach ($route->getDefaults() as $name => $value) + { + $route->setDefault($name, $this->resolve($value)); + } + + $requirements = $route->getRequirements(); + unset($requirements['_scheme']); + unset($requirements['_method']); + + foreach ($requirements as $name => $value) + { + $route->setRequirement($name, $this->resolve($value)); + } + + $route->setPath($this->resolve($route->getPath())); + $route->setHost($this->resolve($route->getHost())); + + $schemes = array(); + foreach ($route->getSchemes() as $scheme) + { + $schemes = array_merge($schemes, explode('|', $this->resolve($scheme))); + } + + $route->setSchemes($schemes); + $methods = array(); + foreach ($route->getMethods() as $method) + { + $methods = array_merge($methods, explode('|', $this->resolve($method))); + } + + $route->setMethods($methods); + $route->setCondition($this->resolve($route->getCondition())); + } + } + + /** + * Recursively replaces placeholders with the service container parameters. + * + * @param mixed $value The source which might contain "%placeholders%" + * + * @return mixed The source with the placeholders replaced by the container + * parameters. Arrays are resolved recursively. + * + * @throws ParameterNotFoundException When a placeholder does not exist as a container parameter + * @throws RuntimeException When a container value is not a string or a numeric value + */ + private function resolve($value) + { + if (is_array($value)) + { + foreach ($value as $key => $val) + { + $value[$key] = $this->resolve($val); + } + + return $value; + } + + if (!is_string($value)) + { + return $value; + } + + $container = $this->container; + $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) + { + // skip %% + if (!isset($match[1])) + { + return '%%'; + } + + $resolved = $container->getParameter($match[1]); + if (is_string($resolved) || is_numeric($resolved)) + { + return (string) $resolved; + } + + throw new RuntimeException(sprintf( + 'The container parameter "%s", used in the route configuration value "%s", '. + 'must be a string or numeric, but it is of type %s.', + $match[1], + $value, + gettype($resolved) + ) + ); + }, $value); + + return str_replace('%%', '%', $escapedValue); + } } -- cgit v1.2.1 From 0799a4808d82c3deafc4d9b74dc777b88ee9862f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 8 Oct 2015 23:16:40 +0200 Subject: [ticket/14225] Inject the loader resolver when using the delegating loader PHPBB3-14225 --- phpBB/phpbb/routing/loader_resolver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/loader_resolver.php b/phpBB/phpbb/routing/loader_resolver.php index e335051444..13fbc6405c 100644 --- a/phpBB/phpbb/routing/loader_resolver.php +++ b/phpBB/phpbb/routing/loader_resolver.php @@ -40,6 +40,7 @@ class loader_resolver implements LoaderResolverInterface { if ($loader->supports($resource, $type)) { + $loader->setResolver($this); return $loader; } } -- cgit v1.2.1 From 8f5a0ad6f73e7b7757b02c827436384c96069b5a Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 24 Jul 2015 09:20:50 +0200 Subject: [ticket/14039] Revamp updater PHPBB3-14039 --- .../installer_resources_locator.php | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 phpBB/phpbb/routing/resources_locator/installer_resources_locator.php (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/resources_locator/installer_resources_locator.php b/phpBB/phpbb/routing/resources_locator/installer_resources_locator.php new file mode 100644 index 0000000000..42cd0f11af --- /dev/null +++ b/phpBB/phpbb/routing/resources_locator/installer_resources_locator.php @@ -0,0 +1,78 @@ + + * @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\routing\resources_locator; + +use phpbb\filesystem\filesystem_interface; + +/** + * Locates the yaml routing resources taking update directories into consideration + */ +class installer_resources_locator implements resources_locator_interface +{ + /** + * phpBB's filesystem handler + * + * @var filesystem_interface + */ + protected $filesystem; + + /** + * phpBB root path + * + * @var string + */ + protected $phpbb_root_path; + + /** + * Name of the current environment + * + * @var string + */ + protected $environment; + + /** + * Construct method + * + * @param filesystem_interface $filesystem phpBB's filesystem handler + * @param string $phpbb_root_path phpBB root path + * @param string $environment Name of the current environment + */ + public function __construct(filesystem_interface $filesystem, $phpbb_root_path, $environment) + { + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + $this->environment = $environment; + } + + /** + * {@inheritdoc} + */ + public function locate_resources() + { + if ($this->filesystem->exists($this->phpbb_root_path . 'install/update/new/config')) + { + $resources = array( + array('install/update/new/config/' . $this->environment . '/routing/environment.yml', 'yaml') + ); + } + else + { + $resources = array( + array('config/' . $this->environment . '/routing/environment.yml', 'yaml') + ); + } + + return $resources; + } +} -- cgit v1.2.1 From 56c2caf6c0778c0da48fe0ac688c893777b89ee4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 23 Mar 2016 22:48:58 +0100 Subject: [ticket/14555] Uniformize cache directory usages PHPBB3-14555 --- phpBB/phpbb/routing/router.php | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index 5d237b6433..f19886fb0b 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -48,13 +48,6 @@ class router implements RouterInterface */ protected $loader; - /** - * phpBB root path - * - * @var string - */ - protected $phpbb_root_path; - /** * PHP file extensions * @@ -62,13 +55,6 @@ class router implements RouterInterface */ protected $php_ext; - /** - * Name of the current environment - * - * @var string - */ - protected $environment; - /** * @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface|null */ @@ -89,25 +75,28 @@ class router implements RouterInterface */ protected $route_collection; + /** + * @var string + */ + protected $cache_dir; + /** * Construct method * * @param ContainerInterface $container DI container * @param resources_locator_interface $resources_locator Resources locator * @param LoaderInterface $loader Resources loader - * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP file extension - * @param string $environment Name of the current environment + * @param string $cache_dir phpBB cache directory */ - public function __construct(ContainerInterface $container, resources_locator_interface $resources_locator, LoaderInterface $loader, $phpbb_root_path, $php_ext, $environment) + public function __construct(ContainerInterface $container, resources_locator_interface $resources_locator, LoaderInterface $loader, $php_ext, $cache_dir) { $this->container = $container; $this->resources_locator = $resources_locator; $this->loader = $loader; - $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->environment = $environment; $this->context = new RequestContext(); + $this->cache_dir = $cache_dir; } /** @@ -211,7 +200,7 @@ class router implements RouterInterface { try { - $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG')); + $cache = new ConfigCache("{$this->cache_dir}url_matcher.{$this->php_ext}", defined('DEBUG')); if (!$cache->isFresh()) { $dumper = new PhpMatcherDumper($this->get_routes()); @@ -266,7 +255,7 @@ class router implements RouterInterface { try { - $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); + $cache = new ConfigCache("{$this->cache_dir}url_generator.{$this->php_ext}", defined('DEBUG')); if (!$cache->isFresh()) { $dumper = new PhpGeneratorDumper($this->get_routes()); -- cgit v1.2.1 From a5f1ff85634eb8936afd109395fc1d305eaca61e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 27 Mar 2016 20:06:02 +0200 Subject: [ticket/13683] Fix merge into 3.2.x PHPBB3-13683 --- phpBB/phpbb/routing/helper.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/helper.php b/phpBB/phpbb/routing/helper.php index f56974a354..011cc4bfef 100644 --- a/phpBB/phpbb/routing/helper.php +++ b/phpBB/phpbb/routing/helper.php @@ -104,6 +104,15 @@ class helper $context = new RequestContext(); $context->fromRequest($this->symfony_request); + if ($this->config['force_server_vars']) + { + $context->setHost($this->config['server_name']); + $context->setScheme(substr($this->config['server_protocol'], 0, -3)); + $context->setHttpPort($this->config['server_port']); + $context->setHttpsPort($this->config['server_port']); + $context->setBaseUrl($this->config['script_path']); + } + $script_name = $this->symfony_request->getScriptName(); $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); @@ -119,7 +128,7 @@ class helper $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); // We need to update the base url to move to the directory of the app.php file if the current script is not app.php - if ($page_name !== 'app.php') + if ($page_name !== 'app.php' && !$this->config['force_server_vars']) { if (empty($this->config['enable_mod_rewrite'])) { -- cgit v1.2.1 From ff9632261e93d5f309541babd5e1fd48530e4c43 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 30 Mar 2016 22:22:38 +0200 Subject: [ticket/13683] Removes extra / in script_path PHPBB3-13683 --- phpBB/phpbb/routing/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/routing') diff --git a/phpBB/phpbb/routing/helper.php b/phpBB/phpbb/routing/helper.php index 011cc4bfef..c15608dce5 100644 --- a/phpBB/phpbb/routing/helper.php +++ b/phpBB/phpbb/routing/helper.php @@ -110,7 +110,7 @@ class helper $context->setScheme(substr($this->config['server_protocol'], 0, -3)); $context->setHttpPort($this->config['server_port']); $context->setHttpsPort($this->config['server_port']); - $context->setBaseUrl($this->config['script_path']); + $context->setBaseUrl(rtrim($this->config['script_path'], '/')); } $script_name = $this->symfony_request->getScriptName(); -- cgit v1.2.1