1
0

IURLGenerator.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCP;
  30. /**
  31. * Class to generate URLs
  32. * @since 6.0.0
  33. */
  34. interface IURLGenerator {
  35. /**
  36. * Regex for matching http(s) urls
  37. *
  38. * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing
  39. *
  40. * @since 25.0.0
  41. * @since 29.0.0 changed to match localhost and hostnames with ports
  42. */
  43. public const URL_REGEX = '/' . self::URL_REGEX_NO_MODIFIERS . '/mi';
  44. /**
  45. * Regex for matching http(s) urls (without modifiers for client compatibility)
  46. *
  47. * This is a copy of the frontend regex in core/src/OCP/comments.js, make sure to adjust both when changing
  48. *
  49. * @since 25.0.0
  50. * @since 29.0.0 changed to match localhost and hostnames with ports
  51. */
  52. public const URL_REGEX_NO_MODIFIERS = '(\s|\n|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|\n|$)';
  53. /**
  54. * Returns the URL for a route
  55. * @param string $routeName the name of the route
  56. * @param array $arguments an array with arguments which will be filled into the url
  57. * @return string the url
  58. * @since 6.0.0
  59. */
  60. public function linkToRoute(string $routeName, array $arguments = []): string;
  61. /**
  62. * Returns the absolute URL for a route
  63. * @param string $routeName the name of the route
  64. * @param array $arguments an array with arguments which will be filled into the url
  65. * @return string the absolute url
  66. * @since 8.0.0
  67. */
  68. public function linkToRouteAbsolute(string $routeName, array $arguments = []): string;
  69. /**
  70. * @param string $routeName
  71. * @param array $arguments
  72. * @return string
  73. * @since 15.0.0
  74. */
  75. public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string;
  76. /**
  77. * Returns an URL for an image or file
  78. * @param string $appName the name of the app
  79. * @param string $file the name of the file
  80. * @param array $args array with param=>value, will be appended to the returned url
  81. * The value of $args will be urlencoded
  82. * @return string the url
  83. * @since 6.0.0
  84. */
  85. public function linkTo(string $appName, string $file, array $args = []): string;
  86. /**
  87. * Returns the link to an image, like linkTo but only with prepending img/
  88. * @param string $appName the name of the app
  89. * @param string $file the name of the file
  90. * @return string the url
  91. * @throws \RuntimeException If the image does not exist
  92. * @since 6.0.0
  93. */
  94. public function imagePath(string $appName, string $file): string;
  95. /**
  96. * Makes an URL absolute
  97. * @param string $url the url in the ownCloud host
  98. * @return string the absolute version of the url
  99. * @since 6.0.0
  100. */
  101. public function getAbsoluteURL(string $url): string;
  102. /**
  103. * @param string $key
  104. * @return string url to the online documentation
  105. * @since 8.0.0
  106. */
  107. public function linkToDocs(string $key): string;
  108. /**
  109. * Returns the URL of the default page based on the system configuration
  110. * and the apps visible for the current user
  111. * @return string
  112. * @since 23.0.0
  113. */
  114. public function linkToDefaultPageUrl(): string;
  115. /**
  116. * @return string base url of the current request
  117. * @since 13.0.0
  118. */
  119. public function getBaseUrl(): string;
  120. /**
  121. * @return string webroot part of the base url
  122. * @since 23.0.0
  123. */
  124. public function getWebroot(): string;
  125. }