MediaWiki master
|
A tree-based path routing algorithm. More...
Public Member Functions | |
add ( $template, $userData) | |
Add a template to the matcher. | |
getCacheData () | |
Get a data array for later use by newFromCache(). | |
match ( $path) | |
Match a path against the current match trees. | |
Static Public Member Functions | |
static | newFromCache ( $data) |
Create a PathMatcher from cache data. | |
A tree-based path routing algorithm.
This container builds defined routing templates into a tree, allowing paths to be efficiently matched against all templates. The match time is independent of the number of registered path templates.
Efficient matching comes at the cost of a potentially significant setup time. We measured ~10ms for 1000 templates. Using getCacheData() and newFromCache(), this setup time may be amortized over multiple requests.
Definition at line 16 of file PathMatcher.php.
MediaWiki\Rest\PathTemplateMatcher\PathMatcher::add | ( | $template, | |
$userData ) |
Add a template to the matcher.
The path template consists of components separated by "/". Each component may be either a parameter of the form {paramName}, or a literal string. A parameter matches any input path component, whereas a literal string matches itself.
Path templates must not conflict with each other, that is, any input path must match at most one path template. If a path template conflicts with another already registered, this function throws a PathConflict exception.
string | $template | The path template |
mixed | $userData | User data used to identify the matched route to the caller of match() |
PathConflict|PathSegmentException |
Definition at line 155 of file PathMatcher.php.
References $params.
Referenced by MediaWiki\Rest\Module\MatcherBasedModule\addRoute().
MediaWiki\Rest\PathTemplateMatcher\PathMatcher::getCacheData | ( | ) |
Get a data array for later use by newFromCache().
The internal format is private to PathMatcher, but note that it includes any data passed as $userData to add(). The array returned will be serializable as long as all $userData values are serializable.
Definition at line 57 of file PathMatcher.php.
MediaWiki\Rest\PathTemplateMatcher\PathMatcher::match | ( | $path | ) |
Match a path against the current match trees.
If the path matches a previously added path template, an array will be returned with the following keys:
If the path does not match any template, false is returned.
string | $path |
Definition at line 211 of file PathMatcher.php.
References $path.
|
static |
Create a PathMatcher from cache data.
array | $data | The data array previously returned by getCacheData() |
Definition at line 42 of file PathMatcher.php.