PageRoutableInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace Grav\Common\Page\Interfaces;
  3. /**
  4. * Interface PageRoutableInterface
  5. * @package Grav\Common\Page\Interfaces
  6. */
  7. interface PageRoutableInterface
  8. {
  9. /**
  10. * Returns the page extension, got from the page `url_extension` config and falls back to the
  11. * system config `system.pages.append_url_extension`.
  12. *
  13. * @return string The extension of this page. For example `.html`
  14. */
  15. public function urlExtension();
  16. /**
  17. * Gets and Sets whether or not this Page is routable, ie you can reach it
  18. * via a URL.
  19. * The page must be *routable* and *published*
  20. *
  21. * @param bool|null $var true if the page is routable
  22. * @return bool true if the page is routable
  23. */
  24. public function routable($var = null);
  25. /**
  26. * Gets the URL for a page - alias of url().
  27. *
  28. * @param bool|null $include_host
  29. * @return string the permalink
  30. */
  31. public function link($include_host = false);
  32. /**
  33. * Gets the URL with host information, aka Permalink.
  34. * @return string The permalink.
  35. */
  36. public function permalink();
  37. /**
  38. * Returns the canonical URL for a page
  39. *
  40. * @param bool $include_lang
  41. * @return string
  42. */
  43. public function canonical($include_lang = true);
  44. /**
  45. * Gets the url for the Page.
  46. *
  47. * @param bool $include_host Defaults false, but true would include http://yourhost.com
  48. * @param bool $canonical true to return the canonical URL
  49. * @param bool $include_lang
  50. * @param bool $raw_route
  51. * @return string The url.
  52. */
  53. public function url($include_host = false, $canonical = false, $include_lang = true, $raw_route = false);
  54. /**
  55. * Gets the route for the page based on the route headers if available, else from
  56. * the parents route and the current Page's slug.
  57. *
  58. * @param string|null $var Set new default route.
  59. * @return string|null The route for the Page.
  60. */
  61. public function route($var = null);
  62. /**
  63. * Helper method to clear the route out so it regenerates next time you use it
  64. */
  65. public function unsetRouteSlug();
  66. /**
  67. * Gets and Sets the page raw route
  68. *
  69. * @param string|null $var
  70. * @return string
  71. */
  72. public function rawRoute($var = null);
  73. /**
  74. * Gets the route aliases for the page based on page headers.
  75. *
  76. * @param array|null $var list of route aliases
  77. * @return array The route aliases for the Page.
  78. */
  79. public function routeAliases($var = null);
  80. /**
  81. * Gets the canonical route for this page if its set. If provided it will use
  82. * that value, else if it's `true` it will use the default route.
  83. *
  84. * @param string|null $var
  85. * @return bool|string
  86. */
  87. public function routeCanonical($var = null);
  88. /**
  89. * Gets the redirect set in the header.
  90. *
  91. * @param string|null $var redirect url
  92. * @return string
  93. */
  94. public function redirect($var = null);
  95. /**
  96. * Returns the clean path to the page file
  97. */
  98. public function relativePagePath();
  99. /**
  100. * Gets and sets the path to the folder where the .md for this Page object resides.
  101. * This is equivalent to the filePath but without the filename.
  102. *
  103. * @param string|null $var the path
  104. * @return string|null the path
  105. */
  106. public function path($var = null);
  107. /**
  108. * Get/set the folder.
  109. *
  110. * @param string|null $var Optional path
  111. * @return string|null
  112. */
  113. public function folder($var = null);
  114. /**
  115. * Gets and Sets the parent object for this page
  116. *
  117. * @param PageInterface|null $var the parent page object
  118. * @return PageInterface|null the parent page object if it exists.
  119. */
  120. public function parent(PageInterface $var = null);
  121. /**
  122. * Gets the top parent object for this page. Can return page itself.
  123. *
  124. * @return PageInterface The top parent page object.
  125. */
  126. public function topParent();
  127. /**
  128. * Returns the item in the current position.
  129. *
  130. * @return int|null The index of the current page.
  131. */
  132. public function currentPosition();
  133. /**
  134. * Returns whether or not this page is the currently active page requested via the URL.
  135. *
  136. * @return bool True if it is active
  137. */
  138. public function active();
  139. /**
  140. * Returns whether or not this URI's URL contains the URL of the active page.
  141. * Or in other words, is this page's URL in the current URL
  142. *
  143. * @return bool True if active child exists
  144. */
  145. public function activeChild();
  146. /**
  147. * Returns whether or not this page is the currently configured home page.
  148. *
  149. * @return bool True if it is the homepage
  150. */
  151. public function home();
  152. /**
  153. * Returns whether or not this page is the root node of the pages tree.
  154. *
  155. * @return bool True if it is the root
  156. */
  157. public function root();
  158. }