mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12090] Make provider a service and inject it into the helper
PHPBB3-12090
This commit is contained in:
parent
275910d8b0
commit
07c07171f9
7 changed files with 28 additions and 35 deletions
|
@ -91,10 +91,10 @@ services:
|
||||||
controller.helper:
|
controller.helper:
|
||||||
class: phpbb\controller\helper
|
class: phpbb\controller\helper
|
||||||
arguments:
|
arguments:
|
||||||
- @ext.finder
|
|
||||||
- @template
|
- @template
|
||||||
- @user
|
- @user
|
||||||
- @config
|
- @config
|
||||||
|
- @controller.provider
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
- %core.php_ext%
|
- %core.php_ext%
|
||||||
|
|
||||||
|
@ -105,6 +105,11 @@ services:
|
||||||
- @service_container
|
- @service_container
|
||||||
- @template
|
- @template
|
||||||
|
|
||||||
|
controller.provider:
|
||||||
|
class: phpbb\controller\provider
|
||||||
|
arguments:
|
||||||
|
- @ext.finder
|
||||||
|
|
||||||
cron.task_collection:
|
cron.task_collection:
|
||||||
class: phpbb\di\service_collection
|
class: phpbb\di\service_collection
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
@ -53,8 +53,8 @@ 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($finder);
|
||||||
$routes = $provider->import_paths_from_finder($finder)->find($root_path);
|
$routes = $provider->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',
|
||||||
|
@ -72,8 +72,8 @@ 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();
|
$provider = new \phpbb\controller\provider($finder);
|
||||||
$routes = $provider->import_paths_from_finder($finder)->find($root_path);
|
$routes = $provider->find($root_path);
|
||||||
return new UrlMatcher($routes, $context);
|
return new UrlMatcher($routes, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,16 +58,14 @@ class helper
|
||||||
* @param string $phpbb_root_path phpBB root path
|
* @param string $phpbb_root_path phpBB root path
|
||||||
* @param string $php_ext PHP extension
|
* @param string $php_ext PHP extension
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\extension\finder $finder, \phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)
|
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, $phpbb_root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$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);
|
||||||
$provider = new \phpbb\controller\provider();
|
|
||||||
$this->route_collection = $provider->import_paths_from_finder($finder)->find($this->phpbb_root_path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,28 +31,20 @@ class provider
|
||||||
* @param array() $routing_files Array of strings containing paths
|
* @param array() $routing_files Array of strings containing paths
|
||||||
* to YAML files holding route information
|
* to YAML files holding route information
|
||||||
*/
|
*/
|
||||||
public function __construct($routing_files = array())
|
public function __construct(\phpbb\extension\finder $finder = null, $routing_files = array())
|
||||||
{
|
{
|
||||||
$this->routing_files = $routing_files;
|
$this->routing_files = $routing_files;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if ($finder)
|
||||||
* Locate paths containing routing files
|
|
||||||
* This sets an internal property but does not return the paths.
|
|
||||||
*
|
|
||||||
* @return The current instance of this object for method chaining
|
|
||||||
*/
|
|
||||||
public function import_paths_from_finder(\phpbb\extension\finder $finder)
|
|
||||||
{
|
{
|
||||||
// We hardcode the path to the core config directory
|
// We hardcode the path to the core config directory
|
||||||
// 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($this->routing_files, array('config/routing.yml'), array_keys($finder
|
||||||
->directory('config')
|
->directory('config')
|
||||||
->suffix('routing.yml')
|
->suffix('routing.yml')
|
||||||
->find()
|
->find()
|
||||||
));
|
));
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,10 +31,8 @@ class phpbb_controller_controller_test extends phpbb_test_case
|
||||||
|
|
||||||
public function test_provider()
|
public function test_provider()
|
||||||
{
|
{
|
||||||
$provider = new \phpbb\controller\provider;
|
$provider = new \phpbb\controller\provider($this->extension_manager->get_finder());
|
||||||
$routes = $provider
|
$routes = $provider->find(__DIR__);
|
||||||
->import_paths_from_finder($this->extension_manager->get_finder())
|
|
||||||
->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->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller'));
|
$this->assertInstanceOf('Symfony\Component\Routing\Route', $routes->get('core_controller'));
|
||||||
|
|
|
@ -80,7 +80,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
|
public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
|
||||||
{
|
{
|
||||||
$this->helper = new \phpbb\controller\helper($this->finder, $this->template, $this->user, $this->config, dirname(__FILE__) . '/', 'php');
|
$this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, new \phpbb\controller\provider($this->finder), dirname(__FILE__) . '/', 'php');
|
||||||
$this->assertEquals(dirname(__FILE__) . '/' . $expected, $this->helper->route($route, $params, $is_amp, $session_id));
|
$this->assertEquals(dirname(__FILE__) . '/' . $expected, $this->helper->route($route, $params, $is_amp, $session_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
|
||||||
public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
|
public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description)
|
||||||
{
|
{
|
||||||
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||||
$this->helper = new \phpbb\controller\helper($this->finder, $this->template, $this->user, $this->config, dirname(__FILE__) . '/', 'php');
|
$this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, new \phpbb\controller\provider($this->finder), dirname(__FILE__) . '/', 'php');
|
||||||
$this->assertEquals(dirname(__FILE__) . '/' . $expected, $this->helper->route($route, $params, $is_amp, $session_id));
|
$this->assertEquals(dirname(__FILE__) . '/' . $expected, $this->helper->route($route, $params, $is_amp, $session_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||||
$this->helper = new \phpbb\controller\helper($this->finder, $this->template, $this->user, $this->config, dirname(__FILE__) . '/', 'php');
|
$this->helper = new \phpbb\controller\helper($this->template, $this->user, $this->config, new \phpbb\controller\provider($this->finder), dirname(__FILE__) . '/', 'php');
|
||||||
$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper);
|
$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue