Frontcontroller.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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$
  21. */
  22. /**
  23. * @see Zend_Application_Resource_ResourceAbstract
  24. */
  25. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  26. /**
  27. * Front Controller resource
  28. *
  29. * @category Zend
  30. * @package Zend_Application
  31. * @subpackage Resource
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
  36. {
  37. /**
  38. * @var Zend_Controller_Front
  39. */
  40. protected $_front;
  41. /**
  42. * Initialize Front Controller
  43. *
  44. * @return Zend_Controller_Front
  45. */
  46. public function init()
  47. {
  48. $front = $this->getFrontController();
  49. foreach ($this->getOptions() as $key => $value) {
  50. switch (strtolower($key)) {
  51. case 'controllerdirectory':
  52. if (is_string($value)) {
  53. $front->setControllerDirectory($value);
  54. } elseif (is_array($value)) {
  55. foreach ($value as $module => $directory) {
  56. $front->addControllerDirectory($directory, $module);
  57. }
  58. }
  59. break;
  60. case 'modulecontrollerdirectoryname':
  61. $front->setModuleControllerDirectoryName($value);
  62. break;
  63. case 'moduledirectory':
  64. $front->addModuleDirectory($value);
  65. break;
  66. case 'defaultcontrollername':
  67. $front->setDefaultControllerName($value);
  68. break;
  69. case 'defaultaction':
  70. $front->setDefaultAction($value);
  71. break;
  72. case 'defaultmodule':
  73. $front->setDefaultModule($value);
  74. break;
  75. case 'baseurl':
  76. if (!empty($value)) {
  77. $front->setBaseUrl($value);
  78. }
  79. break;
  80. case 'params':
  81. $front->setParams($value);
  82. break;
  83. case 'plugins':
  84. foreach ((array) $value as $pluginClass) {
  85. $stackIndex = null;
  86. if(is_array($pluginClass) &&
  87. isset($pluginClass['class']))
  88. {
  89. if(isset($pluginClass['stackindex'])) {
  90. $stackIndex = $pluginClass['stackindex'];
  91. }
  92. $pluginClass = $pluginClass['class'];
  93. }
  94. $plugin = new $pluginClass();
  95. $front->registerPlugin($plugin, $stackIndex);
  96. }
  97. break;
  98. case 'throwexceptions':
  99. $front->throwExceptions((bool) $value);
  100. break;
  101. case 'actionhelperpaths':
  102. if (is_array($value)) {
  103. foreach ($value as $helperPrefix => $helperPath) {
  104. Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
  105. }
  106. }
  107. break;
  108. default:
  109. $front->setParam($key, $value);
  110. break;
  111. }
  112. }
  113. if (null !== ($bootstrap = $this->getBootstrap())) {
  114. $this->getBootstrap()->frontController = $front;
  115. }
  116. return $front;
  117. }
  118. /**
  119. * Retrieve front controller instance
  120. *
  121. * @return Zend_Controller_Front
  122. */
  123. public function getFrontController()
  124. {
  125. if (null === $this->_front) {
  126. $this->_front = Zend_Controller_Front::getInstance();
  127. }
  128. return $this->_front;
  129. }
  130. }