aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_url_matcher.php
diff options
context:
space:
mode:
authorDavid King <imkingdavid@gmail.com>2012-11-14 16:42:52 -0500
committerDavid King <imkingdavid@gmail.com>2012-11-16 17:05:43 -0500
commitfa43edd8778dffd21146350f1749fad5c0755fb7 (patch)
tree7e119560952c9120a4fbb203246d3c2dae6a7598 /phpBB/includes/functions_url_matcher.php
parent4cb9ec522c7007b99eb5ef44cb1bfdb369478aff (diff)
downloadforums-fa43edd8778dffd21146350f1749fad5c0755fb7.tar
forums-fa43edd8778dffd21146350f1749fad5c0755fb7.tar.gz
forums-fa43edd8778dffd21146350f1749fad5c0755fb7.tar.bz2
forums-fa43edd8778dffd21146350f1749fad5c0755fb7.tar.xz
forums-fa43edd8778dffd21146350f1749fad5c0755fb7.zip
[feature/controller] Further separate url matcher functionality
PHPBB3-10864
Diffstat (limited to 'phpBB/includes/functions_url_matcher.php')
-rw-r--r--phpBB/includes/functions_url_matcher.php85
1 files changed, 61 insertions, 24 deletions
diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php
index 0a6e90703c..f628337dee 100644
--- a/phpBB/includes/functions_url_matcher.php
+++ b/phpBB/includes/functions_url_matcher.php
@@ -8,6 +8,7 @@
*/
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
+use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
/**
@@ -19,50 +20,86 @@ if (!defined('IN_PHPBB'))
}
/**
-* Create and/or return the cached phpbb_url_matcher class
-*
-* If the class already exists, it instantiates it
+* 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 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 ($matcher === false)
+ if (defined('DEBUG'))
{
- $provider = new phpbb_controller_provider();
- $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find());
- $cached_url_matcher_dump = $dumper->dump(array(
- 'class' => 'phpbb_url_matcher',
- ));
+ return phpbb_create_url_matcher($finder, $context);
+ }
- 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);
+ if (phpbb_url_matcher_dumped($root_path, $php_ext) === false)
+ {
+ phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext);
}
- return $matcher;
+ return phpbb_load_url_matcher($context, $root_path, $php_ext);
}
/**
-* Load the cached phpbb_url_matcher class
+* 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 phpbb_url_matcher|bool False if the file doesn't exist
+* @return null
*/
-function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
+function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext)
{
- if (file_exists($root_path . 'cache/url_matcher' . $php_ext))
- {
- include($root_path . 'cache/url_matcher' . $php_ext);
- return new phpbb_url_matcher($context);
- }
+ $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);
+}
- return false;
+/**
+* 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
+*
+* @param RequestContext $context Symfony RequestContext object
+* @param string $root_path Root path
+* @param string $php_ext PHP extension
+* @return phpbb_url_matcher
+*/
+function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext)
+{
+ require($root_path . 'cache/url_matcher' . $php_ext);
+ return new phpbb_url_matcher($context);
+}
+
+/**
+* Determine whether we have our dumped URL matcher
+*
+* 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);
}