Navigation.php 3.4 KB

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