UnroutedUrlAssemblerInterface.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\Core\Utility;
  3. /**
  4. * Provides a way to build external or non Drupal local domain URLs.
  5. */
  6. interface UnroutedUrlAssemblerInterface {
  7. /**
  8. * Builds a domain-local or external URL from a URI.
  9. *
  10. * For actual implementations the logic probably has to be split up between
  11. * domain-local URIs and external URLs.
  12. *
  13. * @param string $uri
  14. * A local URI or an external URL being linked to, such as "base:foo"
  15. * or "http://example.com/foo".
  16. * - If you provide a full URL, it will be considered an external URL as
  17. * long as it has an allowed protocol.
  18. * - If you provide only a local URI (e.g. "base:foo"), it will be
  19. * considered a path local to Drupal, but not handled by the routing
  20. * system. The base path (the subdirectory where the front controller
  21. * is found) will be added to the path. Additional query arguments for
  22. * local paths must be supplied in $options['query'], not part of $uri.
  23. * - If your external URL contains a query (e.g. http://example.com/foo?a=b),
  24. * then you can either URL encode the query keys and values yourself and
  25. * include them in $uri, or use $options['query'] to let this method
  26. * URL encode them.
  27. * @param array $options
  28. * (optional) An associative array of additional options, with the following
  29. * elements:
  30. * - 'query': An array of query key/value-pairs (without any URL-encoding) to
  31. * append to the URL.
  32. * - 'fragment': A fragment identifier (named anchor) to append to the URL.
  33. * Do not include the leading '#' character.
  34. * - 'absolute': Defaults to FALSE. Whether to force the output to be an
  35. * absolute link (beginning with http:). Useful for links that will be
  36. * displayed outside the site, such as in an RSS feed.
  37. * - 'https': Whether this URL should point to a secure location. If not
  38. * defined, the current scheme is used, so the user stays on HTTP or HTTPS
  39. * respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
  40. * @param bool $collect_bubbleable_metadata
  41. * (optional) Defaults to FALSE. When TRUE, both the generated URL and its
  42. * associated bubbleable metadata are returned.
  43. *
  44. * @return string|\Drupal\Core\GeneratedUrl
  45. * A string containing a relative or absolute URL.
  46. * When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is
  47. * returned, containing the generated URL plus bubbleable metadata.
  48. *
  49. * @throws \InvalidArgumentException
  50. * Thrown when the passed in path has no scheme.
  51. */
  52. public function assemble($uri, array $options = [], $collect_bubbleable_metadata = FALSE);
  53. }