aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_url_matcher.php
blob: c5d681511982117034a73c7f45ffc1b4171f8197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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, $root_path);
	}

	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($root_path);
	$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, $root_path)
{
	$provider = new \phpbb\controller\provider();
	$routes = $provider->import_paths_from_finder($finder)->find($root_path);
	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);
}