Uri.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Navigation
  17. * @subpackage Page
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Navigation_Page_Abstract
  24. */
  25. require_once 'Zend/Navigation/Page.php';
  26. /**
  27. * Represents a page that is defined by specifying a URI
  28. *
  29. * @category Zend
  30. * @package Zend_Navigation
  31. * @subpackage Page
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Navigation_Page_Uri extends Zend_Navigation_Page
  36. {
  37. /**
  38. * Page URI
  39. *
  40. * @var string|null
  41. */
  42. protected $_uri = null;
  43. /**
  44. * Sets page URI
  45. *
  46. * @param string $uri page URI, must a string or null
  47. * @return Zend_Navigation_Page_Uri fluent interface, returns self
  48. * @throws Zend_Navigation_Exception if $uri is invalid
  49. */
  50. public function setUri($uri)
  51. {
  52. if (null !== $uri && !is_string($uri)) {
  53. require_once 'Zend/Navigation/Exception.php';
  54. throw new Zend_Navigation_Exception(
  55. 'Invalid argument: $uri must be a string or null');
  56. }
  57. $this->_uri = $uri;
  58. return $this;
  59. }
  60. /**
  61. * Returns URI
  62. *
  63. * @return string
  64. */
  65. public function getUri()
  66. {
  67. return $this->_uri;
  68. }
  69. /**
  70. * Returns href for this page
  71. *
  72. * @return string
  73. */
  74. public function getHref()
  75. {
  76. $uri = $this->getUri();
  77. $fragment = $this->getFragment();
  78. if (null !== $fragment) {
  79. if ('#' == substr($uri, -1)) {
  80. return $uri . $fragment;
  81. } else {
  82. return $uri . '#' . $fragment;
  83. }
  84. }
  85. return $uri;
  86. }
  87. // Public methods:
  88. /**
  89. * Returns an array representation of the page
  90. *
  91. * @return array
  92. */
  93. public function toArray()
  94. {
  95. return array_merge(
  96. parent::toArray(),
  97. array(
  98. 'uri' => $this->getUri()
  99. ));
  100. }
  101. }