mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[feature/controller] Further separate url matcher functionality
PHPBB3-10864
This commit is contained in:
parent
4cb9ec522c
commit
fa43edd877
2 changed files with 65 additions and 30 deletions
|
@ -50,8 +50,6 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface
|
||||||
*/
|
*/
|
||||||
public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext)
|
public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$this->template = $template;
|
|
||||||
$this->user = $user;
|
|
||||||
$this->finder = $finder;
|
$this->finder = $finder;
|
||||||
$this->root_path = $root_path;
|
$this->root_path = $root_path;
|
||||||
$this->php_ext = $php_ext;
|
$this->php_ext = $php_ext;
|
||||||
|
@ -71,11 +69,11 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface
|
||||||
$context = new RequestContext();
|
$context = new RequestContext();
|
||||||
$context->fromRequest($request);
|
$context->fromRequest($request);
|
||||||
|
|
||||||
if (!function_exists('phpbb_create_url_matcher'))
|
if (!function_exists('phpbb_load_url_matcher'))
|
||||||
{
|
{
|
||||||
include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext);
|
include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext);
|
||||||
}
|
}
|
||||||
$matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext);
|
$matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext);
|
||||||
|
|
||||||
$router_listener = new RouterListener($matcher, $context);
|
$router_listener = new RouterListener($matcher, $context);
|
||||||
$router_listener->onKernelRequest($event);
|
$router_listener->onKernelRequest($event);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
|
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
|
||||||
|
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||||
use Symfony\Component\Routing\RequestContext;
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,50 +20,86 @@ if (!defined('IN_PHPBB'))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and/or return the cached phpbb_url_matcher class
|
* Create a new UrlMatcher class and dump it into the cache file
|
||||||
*
|
|
||||||
* If the class already exists, it instantiates it
|
|
||||||
*
|
*
|
||||||
* @param phpbb_extension_finder $finder Extension finder
|
* @param phpbb_extension_finder $finder Extension finder
|
||||||
* @param RequestContext $context Symfony RequestContext object
|
* @param RequestContext $context Symfony RequestContext object
|
||||||
* @param string $root_path Root path
|
* @param string $root_path Root path
|
||||||
* @param string $php_ext PHP extension
|
* @param string $php_ext PHP extension
|
||||||
* @return phpbb_url_matcher
|
* @return null
|
||||||
*/
|
*/
|
||||||
function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
|
function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
|
||||||
{
|
{
|
||||||
$matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext);
|
if (defined('DEBUG'))
|
||||||
if ($matcher === false)
|
|
||||||
{
|
{
|
||||||
$provider = new phpbb_controller_provider();
|
return phpbb_create_url_matcher($finder, $context);
|
||||||
$dumper = new PhpMatcherDumper($provider->get_paths($finder)->find());
|
|
||||||
$cached_url_matcher_dump = $dumper->dump(array(
|
|
||||||
'class' => 'phpbb_url_matcher',
|
|
||||||
));
|
|
||||||
|
|
||||||
file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump);
|
|
||||||
return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $matcher;
|
if (phpbb_url_matcher_dumped($root_path, $php_ext) === false)
|
||||||
|
{
|
||||||
|
phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
return phpbb_load_url_matcher($context, $root_path, $php_ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new UrlMatcher class and dump it into the cache file
|
||||||
|
*
|
||||||
|
* @param phpbb_extension_finder $finder Extension finder
|
||||||
|
* @param RequestContext $context Symfony RequestContext object
|
||||||
|
* @param string $root_path Root path
|
||||||
|
* @param string $php_ext PHP extension
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
|
||||||
|
{
|
||||||
|
$provider = new phpbb_controller_provider();
|
||||||
|
$dumper = new PhpMatcherDumper($provider->get_paths($finder)->find());
|
||||||
|
$cached_url_matcher_dump = $dumper->dump(array(
|
||||||
|
'class' => 'phpbb_url_matcher',
|
||||||
|
));
|
||||||
|
|
||||||
|
file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a non-cached UrlMatcher
|
||||||
|
*
|
||||||
|
* @param phpbb_extension_finder $finder Extension finder
|
||||||
|
* @param RequestContext $context Symfony RequestContext object
|
||||||
|
* @return UrlMatcher
|
||||||
|
*/
|
||||||
|
function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context)
|
||||||
|
{
|
||||||
|
$provider = new phpbb_controller_provider();
|
||||||
|
return new UrlMatcher($provider->get_paths($finder)->find(), $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the cached phpbb_url_matcher class
|
* Load the cached phpbb_url_matcher class
|
||||||
*
|
*
|
||||||
* @param phpbb_extension_finder $finder Extension finder
|
|
||||||
* @param RequestContext $context Symfony RequestContext object
|
* @param RequestContext $context Symfony RequestContext object
|
||||||
* @param string $root_path Root path
|
* @param string $root_path Root path
|
||||||
* @param string $php_ext PHP extension
|
* @param string $php_ext PHP extension
|
||||||
* @return phpbb_url_matcher|bool False if the file doesn't exist
|
* @return phpbb_url_matcher
|
||||||
*/
|
*/
|
||||||
function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
|
function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext)
|
||||||
{
|
{
|
||||||
if (file_exists($root_path . 'cache/url_matcher' . $php_ext))
|
require($root_path . 'cache/url_matcher' . $php_ext);
|
||||||
{
|
return new phpbb_url_matcher($context);
|
||||||
include($root_path . 'cache/url_matcher' . $php_ext);
|
}
|
||||||
return new phpbb_url_matcher($context);
|
|
||||||
}
|
/**
|
||||||
|
* Determine whether we have our dumped URL matcher
|
||||||
return false;
|
*
|
||||||
|
* The class is automatically dumped to the cache directory
|
||||||
|
*
|
||||||
|
* @param string $root_path Root path
|
||||||
|
* @param string $php_ext PHP extension
|
||||||
|
* @return bool True if it exists, false if not
|
||||||
|
*/
|
||||||
|
function phpbb_url_matcher_dumped($root_path, $php_ext)
|
||||||
|
{
|
||||||
|
return file_exists($root_path . 'cache/url_matcher' . $php_ext);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue