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