diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2012-11-20 23:19:51 -0600 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2012-11-20 23:19:51 -0600 |
commit | 61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e (patch) | |
tree | 210fe8026aecc70a45d48e52c58ef77d43b85787 /phpBB/includes/functions_url_matcher.php | |
parent | 570c5ad3c08378f377385aaff7d3810ccb8db3ff (diff) | |
parent | b453f359ff6dab58b0eaf94548c4e58110fb02ec (diff) | |
download | forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.gz forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.bz2 forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.tar.xz forums-61aa53f91aaf11bb2fdfac3a9cdc24b074b4463e.zip |
Merge branch 'develop' of git://github.com/phpbb/phpbb3 into ticket/11103
Conflicts:
phpBB/config/services.yml
phpBB/index.php
Diffstat (limited to 'phpBB/includes/functions_url_matcher.php')
-rw-r--r-- | phpBB/includes/functions_url_matcher.php | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php new file mode 100644 index 0000000000..7280cb74eb --- /dev/null +++ b/phpBB/includes/functions_url_matcher.php @@ -0,0 +1,106 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2005 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\RequestContext; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* 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_get_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (defined('DEBUG')) + { + return phpbb_create_url_matcher($finder, $context); + } + + if (!phpbb_url_matcher_dumped($root_path, $php_ext)) + { + phpbb_create_dumped_url_matcher($finder, $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 string $root_path Root path +* @param string $php_ext PHP extension +* @return null +*/ +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, $root_path, $php_ext) +{ + $provider = new phpbb_controller_provider(); + $routes = $provider->import_paths_from_finder($finder)->find(); + $dumper = new PhpMatcherDumper($routes); + $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(); + $routes = $provider->import_paths_from_finder($finder)->find(); + return new UrlMatcher($routes, $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); +} |