Quellcode durchsuchen

Zend_Nav Allow to set a default page type

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22882 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak vor 15 Jahren
Ursprung
Commit
608830836e

+ 4 - 0
library/Zend/Application/Resource/Navigation.php

@@ -58,6 +58,10 @@ class Zend_Application_Resource_Navigation
             $options = $this->getOptions();
             $pages = isset($options['pages']) ? $options['pages'] : array();
             $this->_container = new Zend_Navigation($pages);
+            
+            if(isset($options['defaultPageType'])) {
+                Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']);
+            }
         }
 
         $this->store();

+ 26 - 0
library/Zend/Navigation/Page.php

@@ -136,6 +136,13 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
      */
     protected $_properties = array();
 
+    /**
+     * The type of page to use when it wasn't set
+     * 
+     * @var string
+     */
+    protected static $_defaultPageType;
+    
     // Initialization:
 
     /**
@@ -181,6 +188,11 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
 
         if (isset($options['type'])) {
             $type = $options['type'];
+        } elseif(self::getDefaultPageType()!= null) {
+            $type = self::getDefaultPageType();
+        }
+        
+        if(isset($type)) {
             if (is_string($type) && !empty($type)) {
                 switch (strtolower($type)) {
                     case 'mvc':
@@ -1107,6 +1119,20 @@ abstract class Zend_Navigation_Page extends Zend_Navigation_Container
     {
         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;
+    }
 
     // Abstract methods: