| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Application
- * @subpackage Resource
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @see Zend_Application_Resource_ResourceAbstract
- */
- require_once 'Zend/Application/Resource/ResourceAbstract.php';
- /**
- * Front Controller resource
- *
- * @category Zend
- * @package Zend_Application
- * @subpackage Resource
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
- {
- /**
- * @var Zend_Controller_Front
- */
- protected $_front;
- /**
- * Initialize Front Controller
- *
- * @return Zend_Controller_Front
- * @throws Zend_Application_Exception
- */
- public function init()
- {
- $front = $this->getFrontController();
- foreach ($this->getOptions() as $key => $value) {
- switch (strtolower($key)) {
- case 'controllerdirectory':
- if (is_string($value)) {
- $front->setControllerDirectory($value);
- } elseif (is_array($value)) {
- foreach ($value as $module => $directory) {
- $front->addControllerDirectory($directory, $module);
- }
- }
- break;
- case 'modulecontrollerdirectoryname':
- $front->setModuleControllerDirectoryName($value);
- break;
- case 'moduledirectory':
- if (is_string($value)) {
- $front->addModuleDirectory($value);
- } elseif (is_array($value)) {
- foreach ($value as $moduleDir) {
- $front->addModuleDirectory($moduleDir);
- }
- }
- break;
- case 'defaultcontrollername':
- $front->setDefaultControllerName($value);
- break;
- case 'defaultaction':
- $front->setDefaultAction($value);
- break;
- case 'defaultmodule':
- $front->setDefaultModule($value);
- break;
- case 'baseurl':
- if (!empty($value)) {
- $front->setBaseUrl($value);
- }
- break;
- case 'params':
- $front->setParams($value);
- break;
- case 'plugins':
- foreach ((array) $value as $pluginClass) {
- $stackIndex = null;
- if (is_array($pluginClass)) {
- $pluginClass = array_change_key_case($pluginClass, CASE_LOWER);
- if (isset($pluginClass['class'])) {
- if (isset($pluginClass['stackindex'])) {
- $stackIndex = $pluginClass['stackindex'];
- }
- $pluginClass = $pluginClass['class'];
- }
- }
- $plugin = new $pluginClass();
- $front->registerPlugin($plugin, $stackIndex);
- }
- break;
- case 'returnresponse':
- $front->returnResponse((bool) $value);
- break;
- case 'throwexceptions':
- $front->throwExceptions((bool) $value);
- break;
- case 'actionhelperpaths':
- if (is_array($value)) {
- foreach ($value as $helperPrefix => $helperPath) {
- Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
- }
- }
- break;
- case 'dispatcher':
- if (!isset($value['class'])) {
- require_once 'Zend/Application/Exception.php';
- throw new Zend_Application_Exception('You must specify both ');
- }
- if (!isset($value['params'])) {
- $value['params'] = array();
- }
-
- $dispatchClass = $value['class'];
- if (!class_exists($dispatchClass)) {
- require_once 'Zend/Application/Exception.php';
- throw new Zend_Application_Exception('Dispatcher class not found!');
- }
- $front->setDispatcher(new $dispatchClass((array)$value['params']));
- break;
- default:
- $front->setParam($key, $value);
- break;
- }
- }
- if (null !== ($bootstrap = $this->getBootstrap())) {
- $this->getBootstrap()->frontController = $front;
- }
- return $front;
- }
- /**
- * Retrieve front controller instance
- *
- * @return Zend_Controller_Front
- */
- public function getFrontController()
- {
- if (null === $this->_front) {
- $this->_front = Zend_Controller_Front::getInstance();
- }
- return $this->_front;
- }
- }
|