Navigation.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Resource for setting navigation structure
  24. *
  25. * @uses Zend_Application_Resource_ResourceAbstract
  26. * @category Zend
  27. * @package Zend_Application
  28. * @subpackage Resource
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @author Dolf Schimmel
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Application_Resource_Navigation
  34. extends Zend_Application_Resource_ResourceAbstract
  35. {
  36. const DEFAULT_REGISTRY_KEY = 'Zend_Navigation';
  37. /**
  38. * @var Zend_Navigation
  39. */
  40. protected $_container;
  41. /**
  42. * Defined by Zend_Application_Resource_Resource
  43. *
  44. * @return Zend_Navigation
  45. */
  46. public function init()
  47. {
  48. if (!$this->_container) {
  49. $options = $this->getOptions();
  50. $pages = isset($options['pages']) ? $options['pages'] : array();
  51. $this->_container = new Zend_Navigation($pages);
  52. }
  53. $this->store();
  54. return $this->_container;
  55. }
  56. /**
  57. * Stores navigation container in registry or Navigation view helper
  58. *
  59. * @return void
  60. */
  61. public function store()
  62. {
  63. $options = $this->getOptions();
  64. if (isset($options['storage']['registry']) &&
  65. $options['storage']['registry'] == true) {
  66. $this->_storeRegistry();
  67. } else {
  68. $this->_storeHelper();
  69. }
  70. }
  71. /**
  72. * Stores navigation container in the registry
  73. *
  74. * @return void
  75. */
  76. protected function _storeRegistry()
  77. {
  78. $options = $this->getOptions();
  79. $key = !is_numeric($options['storage']['registry']['key'])
  80. ? $options['storage']['registry']['key']
  81. : self::DEFAULT_REGISTRY_KEY;
  82. Zend_Registry::set($key,$this->getContainer());
  83. }
  84. /**
  85. * Stores navigation container in the Navigation helper
  86. *
  87. * @return void
  88. */
  89. protected function _storeHelper()
  90. {
  91. $this->getBootstrap()->bootstrap('view');
  92. $view = $this->getBootstrap()->getPluginResource('view')->getView();
  93. $view->getHelper('navigation')->navigation($this->getContainer());
  94. }
  95. /**
  96. * Returns navigation container
  97. *
  98. * @return Zend_Navigation
  99. */
  100. public function getContainer()
  101. {
  102. return $this->_container;
  103. }
  104. }