|
17 | 17 | /** |
18 | 18 | * UrlGeneratorInterface is the interface that all URL generator classes must implement. |
19 | 19 | * |
| 20 | + * The constants in this interface define the different types of resource references that |
| 21 | + * are declared in RFC 3986: http://tools.ietf.org/html/rfc3986 |
| 22 | + * We are using the term "URL" instead of "URI" as this is more common in web applications |
| 23 | + * and we do not need to distinguish them as the difference is mostly semantical and |
| 24 | + * less technical. Generating URIs, i.e. representation-independent resource identifiers, |
| 25 | + * is also possible. |
| 26 | + * |
20 | 27 | * @author Fabien Potencier <[email protected]> |
21 | 28 | * @author Tobias Schultze <http://tobion.de> |
22 | 29 | * |
|
25 | 32 | interface UrlGeneratorInterface extends RequestContextAwareInterface |
26 | 33 | { |
27 | 34 | /** |
28 | | - * These constants define the different types of resource references that are declared |
29 | | - * in RFC 3986: http://tools.ietf.org/html/rfc3986 |
30 | | - * We are using the term "URL" instead of "URI" as this is more common in web applications |
31 | | - * and we do not need to distinguish them as the difference is mostly semantical and |
32 | | - * less technical. Generating URIs, i.e. representation-independent resource identifiers, |
33 | | - * is still possible. |
| 35 | + * Generates an absolute URL, e.g. "http://example.com/dir/file". |
| 36 | + */ |
| 37 | + const ABSOLUTE_URL = true; |
| 38 | + |
| 39 | + /** |
| 40 | + * Generates an absolute path, e.g. "/dir/file". |
| 41 | + */ |
| 42 | + const ABSOLUTE_PATH = false; |
| 43 | + |
| 44 | + /** |
| 45 | + * Generates a relative path based on the current request path, e.g. "../parent-file". |
| 46 | + * @see UrlGenerator::getRelativePath() |
34 | 47 | */ |
35 | | - const ABSOLUTE_URL = 'url'; |
36 | | - const ABSOLUTE_PATH = 'path'; |
37 | 48 | const RELATIVE_PATH = 'relative'; |
| 49 | + |
| 50 | + /** |
| 51 | + * Generates a network path, e.g. "//example.com/dir/file". |
| 52 | + * Such reference reuses the current scheme but specifies the hostname. |
| 53 | + */ |
38 | 54 | const NETWORK_PATH = 'network'; |
39 | 55 |
|
40 | 56 | /** |
41 | | - * Generates a URL from the given parameters. |
| 57 | + * Generates a URL or path for a specific route based on the given parameters. |
| 58 | + * |
| 59 | + * Parameters that reference placeholders in the route pattern will substitute them in the |
| 60 | + * path or hostname. Extra params are added as query string to the URL. |
| 61 | + * |
| 62 | + * When the passed reference type cannot be generated for the route because it requires a different |
| 63 | + * hostname or scheme than the current one, the method will return a more comprehensive reference |
| 64 | + * that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH |
| 65 | + * but the route requires the https scheme whereas the current scheme is http, it will instead return an |
| 66 | + * ABSOLUTE_URL with the https scheme and the current hostname. This makes sure the generated URL matches |
| 67 | + * the route in any case. |
42 | 68 | * |
43 | | - * If the generator is not able to generate the url, it must throw the RouteNotFoundException |
44 | | - * as documented below. |
| 69 | + * If there is no route with the given name, the generator must throw the RouteNotFoundException. |
45 | 70 | * |
46 | | - * @param string $name The name of the route |
47 | | - * @param mixed $parameters An array of parameters |
48 | | - * @param string $referenceType The type of reference to be generated (see defined constants) |
| 71 | + * @param string $name The name of the route |
| 72 | + * @param mixed $parameters An array of parameters |
| 73 | + * @param Boolean|string $referenceType The type of reference to be generated (one of the constants) |
49 | 74 | * |
50 | 75 | * @return string The generated URL |
51 | 76 | * |
|
0 commit comments