IURLGenerator.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCP;
  9. /**
  10. * Class to generate URLs
  11. * @since 6.0.0
  12. */
  13. interface IURLGenerator {
  14. /**
  15. * Regex for matching http(s) urls
  16. *
  17. * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing
  18. *
  19. * @since 25.0.0
  20. * @since 29.0.0 changed to match localhost and hostnames with ports
  21. */
  22. public const URL_REGEX = '/' . self::URL_REGEX_NO_MODIFIERS . '/mi';
  23. /**
  24. * Regex for matching http(s) urls (without modifiers for client compatibility)
  25. *
  26. * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing
  27. *
  28. * @since 25.0.0
  29. * @since 29.0.0 changed to match localhost and hostnames with ports
  30. */
  31. public const URL_REGEX_NO_MODIFIERS = '(\s|\n|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)';
  32. /**
  33. * Returns the URL for a route
  34. * @param string $routeName the name of the route
  35. * @param array $arguments an array with arguments which will be filled into the url
  36. * @return string the url
  37. * @since 6.0.0
  38. */
  39. public function linkToRoute(string $routeName, array $arguments = []): string;
  40. /**
  41. * Returns the absolute URL for a route
  42. * @param string $routeName the name of the route
  43. * @param array $arguments an array with arguments which will be filled into the url
  44. * @return string the absolute url
  45. * @since 8.0.0
  46. */
  47. public function linkToRouteAbsolute(string $routeName, array $arguments = []): string;
  48. /**
  49. * @param string $routeName
  50. * @param array $arguments
  51. * @return string
  52. * @since 15.0.0
  53. */
  54. public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string;
  55. /**
  56. * Returns an URL for an image or file
  57. * @param string $appName the name of the app
  58. * @param string $file the name of the file
  59. * @param array $args array with param=>value, will be appended to the returned url
  60. * The value of $args will be urlencoded
  61. * @return string the url
  62. * @since 6.0.0
  63. */
  64. public function linkTo(string $appName, string $file, array $args = []): string;
  65. /**
  66. * Returns the link to an image, like linkTo but only with prepending img/
  67. * @param string $appName the name of the app
  68. * @param string $file the name of the file
  69. * @return string the url
  70. * @throws \RuntimeException If the image does not exist
  71. * @since 6.0.0
  72. */
  73. public function imagePath(string $appName, string $file): string;
  74. /**
  75. * Makes an URL absolute
  76. * @param string $url the url in the ownCloud host
  77. * @return string the absolute version of the url
  78. * @since 6.0.0
  79. */
  80. public function getAbsoluteURL(string $url): string;
  81. /**
  82. * @param string $key
  83. * @return string url to the online documentation
  84. * @since 8.0.0
  85. */
  86. public function linkToDocs(string $key): string;
  87. /**
  88. * Returns the URL of the default page based on the system configuration
  89. * and the apps visible for the current user
  90. * @return string
  91. * @since 23.0.0
  92. */
  93. public function linkToDefaultPageUrl(): string;
  94. /**
  95. * @return string base url of the current request
  96. * @since 13.0.0
  97. */
  98. public function getBaseUrl(): string;
  99. /**
  100. * @return string webroot part of the base url
  101. * @since 23.0.0
  102. */
  103. public function getWebroot(): string;
  104. }