Frontcontroller.php 4.1 KB

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