File indexing completed on 2025-03-02 05:29:36

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Navigation
0017  * @subpackage Page
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Navigation_Page_Abstract
0025  */
0026 // require_once 'Zend/Navigation/Page.php';
0027 
0028 /**
0029  * Represents a page that is defined by specifying a URI
0030  *
0031  * @category   Zend
0032  * @package    Zend_Navigation
0033  * @subpackage Page
0034  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0035  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0036  */
0037 class Zend_Navigation_Page_Uri extends Zend_Navigation_Page
0038 {
0039     /**
0040      * Page URI
0041      *
0042      * @var string|null
0043      */
0044     protected $_uri = null;
0045 
0046     /**
0047      * Sets page URI
0048      *
0049      * @param  string $uri                page URI, must a string or null
0050      * @return Zend_Navigation_Page_Uri   fluent interface, returns self
0051      * @throws Zend_Navigation_Exception  if $uri is invalid
0052      */
0053     public function setUri($uri)
0054     {
0055         if (null !== $uri && !is_string($uri)) {
0056             // require_once 'Zend/Navigation/Exception.php';
0057             throw new Zend_Navigation_Exception(
0058                     'Invalid argument: $uri must be a string or null');
0059         }
0060 
0061         $this->_uri = $uri;
0062         return $this;
0063     }
0064 
0065     /**
0066      * Returns URI
0067      *
0068      * @return string
0069      */
0070     public function getUri()
0071     {
0072         return $this->_uri;
0073     }
0074 
0075     /**
0076      * Returns href for this page
0077      *
0078      * @return string
0079      */
0080     public function getHref()
0081     {
0082         $uri = $this->getUri();
0083         
0084         $fragment = $this->getFragment();       
0085         if (null !== $fragment) {
0086             if ('#' == substr($uri, -1)) {
0087                 return $uri . $fragment;
0088             } else {                
0089                 return $uri . '#' . $fragment;
0090             }
0091         }
0092         
0093         return $uri;
0094     }
0095 
0096     // Public methods:
0097 
0098     /**
0099      * Returns an array representation of the page
0100      *
0101      * @return array
0102      */
0103     public function toArray()
0104     {
0105         return array_merge(
0106             parent::toArray(),
0107             array(
0108                 'uri' => $this->getUri()
0109             ));
0110     }
0111 }