web/lib/Zend/Application/Resource/Navigation.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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_Application
       
    17  * @subpackage Resource
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Navigation.php 22882 2010-08-22 14:00:16Z freak $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Application_Resource_ResourceAbstract
       
    25  */
       
    26 require_once 'Zend/Application/Resource/ResourceAbstract.php';
       
    27 
       
    28 
       
    29 /**
       
    30  * Resource for setting navigation structure
       
    31  *
       
    32  * @uses       Zend_Application_Resource_ResourceAbstract
       
    33  * @category   Zend
       
    34  * @package    Zend_Application
       
    35  * @subpackage Resource
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @author     Dolf Schimmel
       
    38  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    39  */
       
    40 class Zend_Application_Resource_Navigation
       
    41     extends Zend_Application_Resource_ResourceAbstract
       
    42 {
       
    43     const DEFAULT_REGISTRY_KEY = 'Zend_Navigation';
       
    44 
       
    45     /**
       
    46      * @var Zend_Navigation
       
    47      */
       
    48     protected $_container;
       
    49 
       
    50     /**
       
    51      * Defined by Zend_Application_Resource_Resource
       
    52      *
       
    53      * @return Zend_Navigation
       
    54      */
       
    55     public function init()
       
    56     {
       
    57         if (!$this->_container) {
       
    58             $options = $this->getOptions();
       
    59             $pages = isset($options['pages']) ? $options['pages'] : array();
       
    60             $this->_container = new Zend_Navigation($pages);
       
    61             
       
    62             if(isset($options['defaultPageType'])) {
       
    63                 Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']);
       
    64             }
       
    65         }
       
    66 
       
    67         $this->store();
       
    68         return $this->_container;
       
    69     }
       
    70 
       
    71     /**
       
    72      * Stores navigation container in registry or Navigation view helper
       
    73      *
       
    74      * @return void
       
    75      */
       
    76     public function store()
       
    77     {
       
    78         $options = $this->getOptions();
       
    79         if (isset($options['storage']['registry']) &&
       
    80             $options['storage']['registry'] == true) {
       
    81             $this->_storeRegistry();
       
    82         } else {
       
    83             $this->_storeHelper();
       
    84         }
       
    85     }
       
    86 
       
    87     /**
       
    88      * Stores navigation container in the registry
       
    89      *
       
    90      * @return void
       
    91      */
       
    92     protected function _storeRegistry()
       
    93     {
       
    94         $options = $this->getOptions();
       
    95         if(isset($options['storage']['registry']['key']) &&
       
    96            !is_numeric($options['storage']['registry']['key'])) // see ZF-7461
       
    97         {
       
    98            $key = $options['storage']['registry']['key'];
       
    99         } else {
       
   100             $key = self::DEFAULT_REGISTRY_KEY;
       
   101         }
       
   102 
       
   103         Zend_Registry::set($key,$this->getContainer());
       
   104     }
       
   105 
       
   106     /**
       
   107      * Stores navigation container in the Navigation helper
       
   108      *
       
   109      * @return void
       
   110      */
       
   111     protected function _storeHelper()
       
   112     {
       
   113         $this->getBootstrap()->bootstrap('view');
       
   114         $view = $this->getBootstrap()->view;
       
   115         $view->getHelper('navigation')->navigation($this->getContainer());
       
   116     }
       
   117 
       
   118     /**
       
   119      * Returns navigation container
       
   120      *
       
   121      * @return Zend_Navigation
       
   122      */
       
   123     public function getContainer()
       
   124     {
       
   125         return $this->_container;
       
   126     }
       
   127 }