[ticket/12090] Split finding routes and returning routes into 2 methods

PHPBB3-12090
This commit is contained in:
Joas Schilling 2014-03-09 18:38:21 +01:00
parent 436b1d3577
commit 2eb24d0ace
4 changed files with 25 additions and 10 deletions

View file

@ -54,7 +54,7 @@ function phpbb_get_url_matcher(\phpbb\extension\finder $finder, RequestContext $
function phpbb_create_dumped_url_matcher(\phpbb\extension\finder $finder, $root_path, $php_ext) function phpbb_create_dumped_url_matcher(\phpbb\extension\finder $finder, $root_path, $php_ext)
{ {
$provider = new \phpbb\controller\provider($finder); $provider = new \phpbb\controller\provider($finder);
$routes = $provider->find($root_path); $routes = $provider->find($root_path)->get_routes();
$dumper = new PhpMatcherDumper($routes); $dumper = new PhpMatcherDumper($routes);
$cached_url_matcher_dump = $dumper->dump(array( $cached_url_matcher_dump = $dumper->dump(array(
'class' => 'phpbb_url_matcher', 'class' => 'phpbb_url_matcher',
@ -73,7 +73,7 @@ function phpbb_create_dumped_url_matcher(\phpbb\extension\finder $finder, $root_
function phpbb_create_url_matcher(\phpbb\extension\finder $finder, RequestContext $context, $root_path) function phpbb_create_url_matcher(\phpbb\extension\finder $finder, RequestContext $context, $root_path)
{ {
$provider = new \phpbb\controller\provider($finder); $provider = new \phpbb\controller\provider($finder);
$routes = $provider->find($root_path); $routes = $provider->find($root_path)->get_routes();
return new UrlMatcher($routes, $context); return new UrlMatcher($routes, $context);
} }

View file

@ -66,8 +66,7 @@ class helper
$this->config = $config; $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->route_collection = $provider->find($this->phpbb_root_path); $this->route_collection = $provider->find($this->phpbb_root_path)->get_routes();
} }
/** /**

View file

@ -25,6 +25,12 @@ class provider
*/ */
protected $routing_files; protected $routing_files;
/**
* Collection of the routes in phpBB and all found extensions
* @var RouteCollection
*/
protected $routes;
/** /**
* Construct method * Construct method
* *
@ -48,20 +54,30 @@ class provider
} }
/** /**
* Get a list of controllers and return it * Find a list of controllers and return it
* *
* @param string $base_path Base path to prepend to file paths * @param string $base_path Base path to prepend to file paths
* @return array Array of controllers and their route information * @return null
*/ */
public function find($base_path = '') public function find($base_path = '')
{ {
$routes = new RouteCollection; $this->routes = new RouteCollection;
foreach ($this->routing_files as $file_path) foreach ($this->routing_files as $file_path)
{ {
$loader = new YamlFileLoader(new FileLocator($base_path)); $loader = new YamlFileLoader(new FileLocator($base_path));
$routes->addCollection($loader->load($file_path)); $this->routes->addCollection($loader->load($file_path));
} }
return $routes; return $this;
}
/**
* Get the list of routes
*
* @return RouteCollection Get the route collection
*/
public function get_routes()
{
return $this->routes;
} }
} }

View file

@ -32,7 +32,7 @@ class phpbb_controller_controller_test extends phpbb_test_case
public function test_provider() public function test_provider()
{ {
$provider = new \phpbb\controller\provider($this->extension_manager->get_finder()); $provider = new \phpbb\controller\provider($this->extension_manager->get_finder());
$routes = $provider->find(__DIR__); $routes = $provider->find(__DIR__)->get_routes();
// This will need to be updated if any new routes are defined // This will need to be updated if any new routes are defined
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller')); $this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller'));