aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/routing
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/routing')
-rw-r--r--phpBB/phpbb/routing/router.php97
1 files changed, 61 insertions, 36 deletions
diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php
index 40a829b73f..2f89d4e884 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;
@@ -86,16 +87,24 @@ class router implements RouterInterface
protected $route_collection;
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* 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
+ * @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
*/
- public function __construct(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;
$this->routing_files = $routing_files;
$this->phpbb_root_path = $phpbb_root_path;
@@ -107,25 +116,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';
}
@@ -148,7 +157,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));
}
}
@@ -165,7 +174,9 @@ 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 !== null) ? $this->extension_manager->all_enabled(false) : array()
+ )
->find($this->phpbb_root_path);
}
@@ -242,22 +253,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);
+ 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();
+ }
}
/**
@@ -290,22 +308,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);
+ 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();
+ }
}
/**