web/lib/Zend/Navigation/Page.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
--- a/web/lib/Zend/Navigation/Page.php	Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Navigation/Page.php	Thu Mar 21 19:50:53 2013 +0100
@@ -14,9 +14,9 @@
  *
  * @category  Zend
  * @package   Zend_Navigation
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license   http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Page.php 22882 2010-08-22 14:00:16Z freak $
+ * @version    $Id: Page.php 25125 2012-11-16 15:12:06Z rob $
  */
 
 /**
@@ -29,7 +29,7 @@
  *
  * @category  Zend
  * @package   Zend_Navigation
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license   http://framework.zend.com/license/new-bsd     New BSD License
  */
 abstract class Zend_Navigation_Page extends Zend_Navigation_Container
@@ -42,6 +42,20 @@
     protected $_label;
 
     /**
+     * Fragment identifier (anchor identifier)
+     * 
+     * The fragment identifier (anchor identifier) pointing to an anchor within 
+     * a resource that is subordinate to another, primary resource.
+     * The fragment identifier introduced by a hash mark "#".
+     * Example: http://www.example.org/foo.html#bar ("bar" is the fragment identifier)
+     * 
+     * @link http://www.w3.org/TR/html401/intro/intro.html#fragment-uri
+     * 
+     * @var string|null
+     */
+    protected $_fragment;
+
+    /**
      * Page id
      *
      * @var string|null
@@ -70,6 +84,18 @@
     protected $_target;
 
     /**
+     * Accessibility key character
+     *
+     * This attribute assigns an access key to an element. An access key is a
+     * single character from the document character set.
+     *
+     * @link http://www.w3.org/TR/html401/interact/forms.html#access-keys
+     *
+     * @var string|null
+     */
+    protected $_accesskey;
+
+    /**
      * Forward links to other pages
      *
      * @link http://www.w3.org/TR/html4/struct/links.html#h-12.3.1
@@ -137,12 +163,19 @@
     protected $_properties = array();
 
     /**
+     * Custom HTML attributes
+     *
+     * @var array
+     */
+    protected $_customHtmlAttribs = array();
+
+    /**
      * The type of page to use when it wasn't set
-     * 
+     *
      * @var string
      */
     protected static $_defaultPageType;
-    
+
     // Initialization:
 
     /**
@@ -191,7 +224,7 @@
         } elseif(self::getDefaultPageType()!= null) {
             $type = self::getDefaultPageType();
         }
-        
+
         if(isset($type)) {
             if (is_string($type) && !empty($type)) {
                 switch (strtolower($type)) {
@@ -222,7 +255,8 @@
 
         $hasUri = isset($options['uri']);
         $hasMvc = isset($options['action']) || isset($options['controller']) ||
-                  isset($options['module']) || isset($options['route']);
+                  isset($options['module']) || isset($options['route']) ||
+                  isset($options['params']);
 
         if ($hasMvc) {
             require_once 'Zend/Navigation/Page/Mvc.php';
@@ -232,9 +266,14 @@
             return new Zend_Navigation_Page_Uri($options);
         } else {
             require_once 'Zend/Navigation/Exception.php';
-            throw new Zend_Navigation_Exception(
-                'Invalid argument: Unable to determine class to instantiate');
+            
+            $message = 'Invalid argument: Unable to determine class to instantiate';
+            if (isset($options['label'])) {
+                $message .= ' (Page label: ' . $options['label'] . ')';
         }
+            
+            throw new Zend_Navigation_Exception($message);
+    }
     }
 
     /**
@@ -330,6 +369,35 @@
     }
 
     /**
+     * Sets a fragment identifier
+     *
+     * @param  string $fragment   new fragment identifier
+     * @return Zend_Navigation_Page         fluent interface, returns self
+     * @throws Zend_Navigation_Exception    if empty/no string is given
+     */
+    public function setFragment($fragment)
+    {
+        if (null !== $fragment && !is_string($fragment)) {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                    'Invalid argument: $fragment must be a string or null');
+        }
+ 
+        $this->_fragment = $fragment;
+        return $this;
+    }
+    
+     /**
+     * Returns fragment identifier
+     *
+     * @return string|null  fragment identifier
+     */
+    public function getFragment()
+    {
+        return $this->_fragment;
+    }
+
+    /**
      * Sets page id
      *
      * @param  string|null $id            [optional] id to set. Default is null,
@@ -451,6 +519,40 @@
     }
 
     /**
+     * Sets access key for this page
+     *
+     * @param  string|null $character     [optional] access key to set. Default
+     *                                    is null, which sets no access key.
+     * @return Zend_Navigation_Page       fluent interface, returns self
+     * @throws Zend_Navigation_Exception  if access key is not string or null or
+     *                                    if the string length not equal to one
+     */
+    public function setAccesskey($character = null)
+    {
+        if (null !== $character
+            && (!is_string($character) || 1 != strlen($character)))
+        {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                'Invalid argument: $character must be a single character or null'
+            );
+        }
+ 
+        $this->_accesskey = $character;
+        return $this;
+    }
+
+     /**
+     * Returns page access key
+     *
+     * @return string|null  page access key or null
+     */
+    public function getAccesskey()
+    {
+        return $this->_accesskey;
+    }
+
+    /**
      * Sets the page's forward links to other pages
      *
      * This method expects an associative array of forward links to other pages,
@@ -577,6 +679,119 @@
     }
 
     /**
+     * Sets a single custom HTML attribute
+     *
+     * @param  string      $name            name of the HTML attribute
+     * @param  string|null $value           value for the HTML attribute
+     * @return Zend_Navigation_Page         fluent interface, returns self
+     * @throws Zend_Navigation_Exception    if name is not string or value is
+     *                                      not null or a string
+     */
+    public function setCustomHtmlAttrib($name, $value)
+    {
+        if (!is_string($name)) {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                'Invalid argument: $name must be a string'
+            );
+        }
+
+        if (null !== $value && !is_string($value)) {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                'Invalid argument: $value must be a string or null'
+            );
+        }
+
+        if (null === $value && isset($this->_customHtmlAttribs[$name])) {
+            unset($this->_customHtmlAttribs[$name]);
+        } else {
+            $this->_customHtmlAttribs[$name] = $value;
+        }
+
+        return $this;
+    }
+
+    /**
+     * Returns a single custom HTML attributes by name
+     *
+     * @param  string $name                 name of the HTML attribute
+     * @return string|null                  value for the HTML attribute or null
+     * @throws Zend_Navigation_Exception    if name is not string
+     */
+    public function getCustomHtmlAttrib($name)
+    {
+        if (!is_string($name)) {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                'Invalid argument: $name must be a string'
+            );
+        }
+
+        if (isset($this->_customHtmlAttribs[$name])) {
+            return $this->_customHtmlAttribs[$name];
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets multiple custom HTML attributes at once
+     *
+     * @param array $attribs        an associative array of html attributes
+     * @return Zend_Navigation_Page fluent interface, returns self
+     */
+    public function setCustomHtmlAttribs(array $attribs)
+    {
+        foreach ($attribs as $key => $value) {
+            $this->setCustomHtmlAttrib($key, $value);
+        }
+        return $this;
+    }
+
+    /**
+     * Returns all custom HTML attributes as an array
+     *
+     * @return array    an array containing custom HTML attributes
+     */
+    public function getCustomHtmlAttribs()
+    {
+        return $this->_customHtmlAttribs;
+    }
+
+    /**
+     * Removes a custom HTML attribute from the page
+     *
+     * @param  string $name          name of the custom HTML attribute
+     * @return Zend_Navigation_Page  fluent interface, returns self
+     */
+    public function removeCustomHtmlAttrib($name)
+    {
+        if (!is_string($name)) {
+            require_once 'Zend/Navigation/Exception.php';
+            throw new Zend_Navigation_Exception(
+                'Invalid argument: $name must be a string'
+            );
+        }
+
+        if (isset($this->_customHtmlAttribs[$name])) {
+            unset($this->_customHtmlAttribs[$name]);
+        }
+    }
+
+    /**
+     * Clear all custom HTML attributes
+     *
+     * @return Zend_Navigation_Page fluent interface, returns self
+     */
+    public function clearCustomHtmlAttribs()
+    {
+        $this->_customHtmlAttribs = array();
+
+        return $this;
+    }
+
+    /**
      * Sets page order to use in parent container
      *
      * @param  int $order                 [optional] page order in container.
@@ -740,6 +955,9 @@
      */
     public function setVisible($visible = true)
     {
+        if (is_string($visible) && 'false' == strtolower($visible)) {
+            $visible = false;
+        }
         $this->_visible = (bool) $visible;
         return $this;
     }
@@ -1090,21 +1308,25 @@
         return array_merge(
             $this->getCustomProperties(),
             array(
-                'label'     => $this->getlabel(),
-                'id'        => $this->getId(),
-                'class'     => $this->getClass(),
-                'title'     => $this->getTitle(),
-                'target'    => $this->getTarget(),
-                'rel'       => $this->getRel(),
-                'rev'       => $this->getRev(),
-                'order'     => $this->getOrder(),
-                'resource'  => $this->getResource(),
-                'privilege' => $this->getPrivilege(),
-                'active'    => $this->isActive(),
-                'visible'   => $this->isVisible(),
-                'type'      => get_class($this),
-                'pages'     => parent::toArray()
-            ));
+                'label'             => $this->getlabel(),
+                'fragment'          => $this->getFragment(),
+                'id'                => $this->getId(),
+                'class'             => $this->getClass(),
+                'title'             => $this->getTitle(),
+                'target'            => $this->getTarget(),
+                'accesskey'         => $this->getAccesskey(),
+                'rel'               => $this->getRel(),
+                'rev'               => $this->getRev(),
+                'customHtmlAttribs' => $this->getCustomHtmlAttribs(),
+                'order'             => $this->getOrder(),
+                'resource'          => $this->getResource(),
+                'privilege'         => $this->getPrivilege(),
+                'active'            => $this->isActive(),
+                'visible'           => $this->isVisible(),
+                'type'              => get_class($this),
+                'pages'             => parent::toArray()
+            )
+        );
     }
 
     // Internal methods:
@@ -1119,17 +1341,17 @@
     {
         return str_replace(' ', '', ucwords(str_replace('_', ' ', $property)));
     }
-    
+
     public static function setDefaultPageType($type = null) {
         if($type !== null && !is_string($type)) {
             throw new Zend_Navigation_Exception(
                 'Cannot set default page type: type is no string but should be'
             );
         }
-        
+
         self::$_defaultPageType = $type;
     }
-    
+
     public static function getDefaultPageType() {
         return self::$_defaultPageType;
     }