[ticket/11948] Allow resource importing for routing

PHPBB3-11948
This commit is contained in:
Joas Schilling 2013-10-21 21:52:48 +02:00
parent bd86dea16c
commit 51561ed538
4 changed files with 12 additions and 9 deletions

View file

@ -32,7 +32,7 @@ function phpbb_get_url_matcher(\phpbb\extension\finder $finder, RequestContext $
{ {
if (defined('DEBUG')) if (defined('DEBUG'))
{ {
return phpbb_create_url_matcher($finder, $context); return phpbb_create_url_matcher($finder, $context, $root_path);
} }
if (!phpbb_url_matcher_dumped($root_path, $php_ext)) if (!phpbb_url_matcher_dumped($root_path, $php_ext))
@ -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(); $provider = new \phpbb\controller\provider();
$routes = $provider->import_paths_from_finder($finder)->find(); $routes = $provider->import_paths_from_finder($finder)->find($root_path);
$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',
@ -70,10 +70,10 @@ function phpbb_create_dumped_url_matcher(\phpbb\extension\finder $finder, $root_
* @param RequestContext $context Symfony RequestContext object * @param RequestContext $context Symfony RequestContext object
* @return UrlMatcher * @return UrlMatcher
*/ */
function phpbb_create_url_matcher(\phpbb\extension\finder $finder, RequestContext $context) function phpbb_create_url_matcher(\phpbb\extension\finder $finder, RequestContext $context, $root_path)
{ {
$provider = new \phpbb\controller\provider(); $provider = new \phpbb\controller\provider();
$routes = $provider->import_paths_from_finder($finder)->find(); $routes = $provider->import_paths_from_finder($finder)->find($root_path);
return new UrlMatcher($routes, $context); return new UrlMatcher($routes, $context);
} }

View file

@ -56,8 +56,7 @@ class provider
// because the finder cannot find it // because the finder cannot find it
$this->routing_files = array_merge(array('config/routing.yml'), array_keys($finder $this->routing_files = array_merge(array('config/routing.yml'), array_keys($finder
->directory('config') ->directory('config')
->prefix('routing') ->suffix('routing.yml')
->suffix('.yml')
->find() ->find()
)); ));
@ -75,8 +74,8 @@ class provider
$routes = new RouteCollection; $routes = new RouteCollection;
foreach ($this->routing_files as $file_path) foreach ($this->routing_files as $file_path)
{ {
$loader = new YamlFileLoader(new FileLocator(dirname($base_path . $file_path))); $loader = new YamlFileLoader(new FileLocator($base_path));
$routes->addCollection($loader->load(basename($file_path))); $routes->addCollection($loader->load($file_path));
} }
return $routes; return $routes;

View file

@ -34,7 +34,7 @@ class phpbb_controller_controller_test extends phpbb_test_case
$provider = new \phpbb\controller\provider; $provider = new \phpbb\controller\provider;
$routes = $provider $routes = $provider
->import_paths_from_finder($this->extension_manager->get_finder()) ->import_paths_from_finder($this->extension_manager->get_finder())
->find('./tests/controller/'); ->find(__DIR__);
// 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->assertEquals(3, sizeof($routes)); $this->assertEquals(3, sizeof($routes));

View file

@ -1,3 +1,7 @@
controller1: controller1:
pattern: /foo pattern: /foo
defaults: { _controller: foo.controller:handle } defaults: { _controller: foo.controller:handle }
include_controller2:
resource: "routing_2.yml"
prefix: /foo