Frontcontroller.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $plugin = new $pluginClass();
  86. $front->registerPlugin($plugin);
  87. }
  88. break;
  89. case 'throwexceptions':
  90. $front->throwExceptions((bool) $value);
  91. break;
  92. case 'actionhelperpaths':
  93. if (is_array($value)) {
  94. foreach ($value as $helperPrefix => $helperPath) {
  95. Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
  96. }
  97. }
  98. break;
  99. default:
  100. $front->setParam($key, $value);
  101. break;
  102. }
  103. }
  104. if (null !== ($bootstrap = $this->getBootstrap())) {
  105. $this->getBootstrap()->frontController = $front;
  106. }
  107. return $front;
  108. }
  109. /**
  110. * Retrieve front controller instance
  111. *
  112. * @return Zend_Controller_Front
  113. */
  114. public function getFrontController()
  115. {
  116. if (null === $this->_front) {
  117. $this->_front = Zend_Controller_Front::getInstance();
  118. }
  119. return $this->_front;
  120. }
  121. }