2
0

Navigation.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if(isset($options['storage']) &&
  80. isset($options['storage']['registry']) &&
  81. isset($options['storage']['registry']['key']))
  82. {
  83. $key = $options['storage']['registry']['key'];
  84. } else {
  85. $key = self::DEFAULT_REGISTRY_KEY;
  86. }
  87. Zend_Registry::set($key,$this->getContainer());
  88. }
  89. /**
  90. * Stores navigation container in the Navigation helper
  91. *
  92. * @return void
  93. */
  94. protected function _storeHelper()
  95. {
  96. $this->getBootstrap()->bootstrap('view');
  97. $view = $this->getBootstrap()->view;
  98. $view->getHelper('navigation')->navigation($this->getContainer());
  99. }
  100. /**
  101. * Returns navigation container
  102. *
  103. * @return Zend_Navigation
  104. */
  105. public function getContainer()
  106. {
  107. return $this->_container;
  108. }
  109. }