Uri.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ JEF8eOP0OgjNoJssHmcR5lgTR7unYXmS2gaT8xU1r2Y=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * navigation page uri class
  14. */
  15. namespace Cube\Navigation\Page;
  16. use Cube\Controller\Front;
  17. class Uri extends AbstractPage
  18. {
  19. /**
  20. *
  21. * uri address
  22. *
  23. * @var string
  24. */
  25. protected $_uri;
  26. /**
  27. *
  28. * get uri
  29. *
  30. * @return string
  31. */
  32. public function getParams()
  33. {
  34. return $this->_uri;
  35. }
  36. /**
  37. *
  38. * get uri
  39. *
  40. * @return string
  41. */
  42. public function getUri()
  43. {
  44. return $this->_uri;
  45. }
  46. /**
  47. *
  48. * set uri
  49. *
  50. * @param string $uri
  51. * @return \Cube\Navigation\Page\Uri
  52. * @throws \InvalidArgumentException
  53. */
  54. public function setUri($uri)
  55. {
  56. if (!is_string($uri) && $uri !== null) {
  57. throw new \InvalidArgumentException(sprintf(
  58. "'uri' must be a string or null, %s given.", gettype($uri)));
  59. }
  60. $this->_uri = $uri;
  61. return $this;
  62. }
  63. /**
  64. *
  65. * check if a page is active, based on the request uri
  66. *
  67. * @param bool $recursive check in subpages as well, and if a subpage is active, return the current page as active
  68. * @return bool returns active status
  69. */
  70. public function isActive($recursive = false)
  71. {
  72. if (!$this->_active) {
  73. $frontController = Front::getInstance();
  74. $request = $frontController->getRequest();
  75. if ($request->matchRequestUri($this->_uri, false)) {
  76. $this->_active = true;
  77. return true;
  78. }
  79. }
  80. return parent::isActive($recursive);
  81. }
  82. }