You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.4 KiB

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