forked from nikic/FastRoute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouteGenerator.php
executable file
·57 lines (55 loc) · 2.12 KB
/
RouteGenerator.php
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
<?php
namespace FastRoute;
/**
* Generate routes.
*
* Implementations should collect any necessary data in their constructors.
*/
interface RouteGenerator {
/**
* Generates a route string from a parsed route data array.
*
* The expected output is defined using an example:
*
* Consider the route string
* `'/fixedRoutePart/{varName}[/moreFixed/{varName2:\d+}]'`,
* with name "my_route". `{varName}` is interpreted as
* a placeholder and `[...]` is interpreted as an optional route part.
* This matches routes like `"/fixedRoutePart/foo"` and routes like
* `"/fixedRoutePart/foo/moreFixed/42"`. These two forms are referred
* to as "branches".
*
* A route can be generated with this call:
*
* ```php
* $generator = new RouteGenerator($parsedRoutes);
* $generator->gen('my_route', array('varName'=>'hello'));
* --> returns '/fixedRoutePart/hello'
* $generator->gen('my_route', array('varName'=>'hello', 'varName2'=>42));
* --> returns '/fixedRoutePart/hello/moreFixed/42'
* ```
*
* Returns the longest branch that can be generated using the
* given value array. The "longest branch" is the one that matches
* the most placeholders.
*
* Throws BadRouteException if $routename is not known.
*
* Throws BadRouteException if the parameters given don't satisfy any
* possible branch for this route.
*
* At implementation option, may throw a BadRouteException
* if the provided values, converted to strings with the PHP defaults,
* don't match the respective regexes.
* Implementations supporting this option shall inform calling code.
*
* @param string $routename Which route to generate
* @param mixed[] $values (optional) Associative array holding values
* for the placeholders, if any, in the route.
* $values may contain items not referenced by the
* current route. That is not an error.
*
* @return string The route URL.
*/
public function gen($routename, $values = []);
}