Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Routing\Generator;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\Routing\Exception\InvalidParameterException;
|
Chris@0
|
15 use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
Chris@0
|
16 use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
Chris@0
|
17 use Symfony\Component\Routing\RequestContextAwareInterface;
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * UrlGeneratorInterface is the interface that all URL generator classes must implement.
|
Chris@0
|
21 *
|
Chris@0
|
22 * The constants in this interface define the different types of resource references that
|
Chris@0
|
23 * are declared in RFC 3986: http://tools.ietf.org/html/rfc3986
|
Chris@0
|
24 * We are using the term "URL" instead of "URI" as this is more common in web applications
|
Chris@0
|
25 * and we do not need to distinguish them as the difference is mostly semantical and
|
Chris@0
|
26 * less technical. Generating URIs, i.e. representation-independent resource identifiers,
|
Chris@0
|
27 * is also possible.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
30 * @author Tobias Schultze <http://tobion.de>
|
Chris@0
|
31 */
|
Chris@0
|
32 interface UrlGeneratorInterface extends RequestContextAwareInterface
|
Chris@0
|
33 {
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Generates an absolute URL, e.g. "http://example.com/dir/file".
|
Chris@0
|
36 */
|
Chris@0
|
37 const ABSOLUTE_URL = 0;
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * Generates an absolute path, e.g. "/dir/file".
|
Chris@0
|
41 */
|
Chris@0
|
42 const ABSOLUTE_PATH = 1;
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * Generates a relative path based on the current request path, e.g. "../parent-file".
|
Chris@0
|
46 *
|
Chris@0
|
47 * @see UrlGenerator::getRelativePath()
|
Chris@0
|
48 */
|
Chris@0
|
49 const RELATIVE_PATH = 2;
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * Generates a network path, e.g. "//example.com/dir/file".
|
Chris@0
|
53 * Such reference reuses the current scheme but specifies the host.
|
Chris@0
|
54 */
|
Chris@0
|
55 const NETWORK_PATH = 3;
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Generates a URL or path for a specific route based on the given parameters.
|
Chris@0
|
59 *
|
Chris@0
|
60 * Parameters that reference placeholders in the route pattern will substitute them in the
|
Chris@0
|
61 * path or host. Extra params are added as query string to the URL.
|
Chris@0
|
62 *
|
Chris@0
|
63 * When the passed reference type cannot be generated for the route because it requires a different
|
Chris@0
|
64 * host or scheme than the current one, the method will return a more comprehensive reference
|
Chris@0
|
65 * that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH
|
Chris@0
|
66 * but the route requires the https scheme whereas the current scheme is http, it will instead return an
|
Chris@0
|
67 * ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches
|
Chris@0
|
68 * the route in any case.
|
Chris@0
|
69 *
|
Chris@0
|
70 * If there is no route with the given name, the generator must throw the RouteNotFoundException.
|
Chris@0
|
71 *
|
Chris@0
|
72 * The special parameter _fragment will be used as the document fragment suffixed to the final URL.
|
Chris@0
|
73 *
|
Chris@0
|
74 * @param string $name The name of the route
|
Chris@0
|
75 * @param mixed $parameters An array of parameters
|
Chris@0
|
76 * @param int $referenceType The type of reference to be generated (one of the constants)
|
Chris@0
|
77 *
|
Chris@0
|
78 * @return string The generated URL
|
Chris@0
|
79 *
|
Chris@0
|
80 * @throws RouteNotFoundException If the named route doesn't exist
|
Chris@0
|
81 * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
Chris@0
|
82 * @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
Chris@0
|
83 * it does not match the requirement
|
Chris@0
|
84 */
|
Chris@17
|
85 public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH);
|
Chris@0
|
86 }
|