File indexing completed on 2024-12-22 05:36:28

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_Application
0017  * @subpackage Resource
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_Application_Resource_ResourceAbstract
0025  */
0026 // require_once 'Zend/Application/Resource/ResourceAbstract.php';
0027 
0028 
0029 /**
0030  * Resource for setting navigation structure
0031  *
0032  * @uses       Zend_Application_Resource_ResourceAbstract
0033  * @category   Zend
0034  * @package    Zend_Application
0035  * @subpackage Resource
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @author     Dolf Schimmel
0038  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0039  */
0040 class Zend_Application_Resource_Navigation
0041     extends Zend_Application_Resource_ResourceAbstract
0042 {
0043     const DEFAULT_REGISTRY_KEY = 'Zend_Navigation';
0044 
0045     /**
0046      * @var Zend_Navigation
0047      */
0048     protected $_container;
0049 
0050     /**
0051      * Defined by Zend_Application_Resource_Resource
0052      *
0053      * @return Zend_Navigation
0054      */
0055     public function init()
0056     {
0057         if (!$this->_container) {
0058             $options = $this->getOptions();
0059 
0060             if (isset($options['defaultPageType'])) {
0061                 Zend_Navigation_Page::setDefaultPageType(
0062                     $options['defaultPageType']
0063                 );
0064             }
0065 
0066             $pages = isset($options['pages']) ? $options['pages'] : array();
0067             $this->_container = new Zend_Navigation($pages);
0068         }
0069 
0070         $this->store();
0071         return $this->_container;
0072     }
0073 
0074     /**
0075      * Stores navigation container in registry or Navigation view helper
0076      *
0077      * @return void
0078      */
0079     public function store()
0080     {
0081         $options = $this->getOptions();
0082         if (isset($options['storage']['registry']) &&
0083             $options['storage']['registry'] == true) {
0084             $this->_storeRegistry();
0085         } else {
0086             $this->_storeHelper();
0087         }
0088     }
0089 
0090     /**
0091      * Stores navigation container in the registry
0092      *
0093      * @return void
0094      */
0095     protected function _storeRegistry()
0096     {
0097         $options = $this->getOptions();
0098         // see ZF-7461
0099         if (isset($options['storage']['registry']['key'])
0100             && !is_numeric($options['storage']['registry']['key'])
0101         ) {
0102             $key = $options['storage']['registry']['key'];
0103         } else {
0104             $key = self::DEFAULT_REGISTRY_KEY;
0105         }
0106 
0107         Zend_Registry::set($key, $this->getContainer());
0108     }
0109 
0110     /**
0111      * Stores navigation container in the Navigation helper
0112      *
0113      * @return void
0114      */
0115     protected function _storeHelper()
0116     {
0117         $this->getBootstrap()->bootstrap('view');
0118         $view = $this->getBootstrap()->view;
0119         $view->getHelper('navigation')->navigation($this->getContainer());
0120     }
0121 
0122     /**
0123      * Returns navigation container
0124      *
0125      * @return Zend_Navigation
0126      */
0127     public function getContainer()
0128     {
0129         return $this->_container;
0130     }
0131 }