File indexing completed on 2024-12-22 05:36:28
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Application 0017 * @subpackage Resource 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Application_Resource_ResourceAbstract 0025 */ 0026 // require_once 'Zend/Application/Resource/ResourceAbstract.php'; 0027 0028 0029 /** 0030 * Front Controller resource 0031 * 0032 * @category Zend 0033 * @package Zend_Application 0034 * @subpackage Resource 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract 0039 { 0040 /** 0041 * @var Zend_Controller_Front 0042 */ 0043 protected $_front; 0044 0045 /** 0046 * Initialize Front Controller 0047 * 0048 * @return Zend_Controller_Front 0049 * @throws Zend_Application_Exception 0050 */ 0051 public function init() 0052 { 0053 $front = $this->getFrontController(); 0054 0055 foreach ($this->getOptions() as $key => $value) { 0056 switch (strtolower($key)) { 0057 case 'controllerdirectory': 0058 if (is_string($value)) { 0059 $front->setControllerDirectory($value); 0060 } elseif (is_array($value)) { 0061 foreach ($value as $module => $directory) { 0062 $front->addControllerDirectory($directory, $module); 0063 } 0064 } 0065 break; 0066 0067 case 'modulecontrollerdirectoryname': 0068 $front->setModuleControllerDirectoryName($value); 0069 break; 0070 0071 case 'moduledirectory': 0072 if (is_string($value)) { 0073 $front->addModuleDirectory($value); 0074 } elseif (is_array($value)) { 0075 foreach ($value as $moduleDir) { 0076 $front->addModuleDirectory($moduleDir); 0077 } 0078 } 0079 break; 0080 0081 case 'defaultcontrollername': 0082 $front->setDefaultControllerName($value); 0083 break; 0084 0085 case 'defaultaction': 0086 $front->setDefaultAction($value); 0087 break; 0088 0089 case 'defaultmodule': 0090 $front->setDefaultModule($value); 0091 break; 0092 0093 case 'baseurl': 0094 if (!empty($value)) { 0095 $front->setBaseUrl($value); 0096 } 0097 break; 0098 0099 case 'params': 0100 $front->setParams($value); 0101 break; 0102 0103 case 'plugins': 0104 foreach ((array) $value as $pluginClass) { 0105 $stackIndex = null; 0106 if (is_array($pluginClass)) { 0107 $pluginClass = array_change_key_case($pluginClass, CASE_LOWER); 0108 if (isset($pluginClass['class'])) { 0109 if (isset($pluginClass['stackindex'])) { 0110 $stackIndex = $pluginClass['stackindex']; 0111 } 0112 0113 $pluginClass = $pluginClass['class']; 0114 } 0115 } 0116 0117 $plugin = new $pluginClass(); 0118 $front->registerPlugin($plugin, $stackIndex); 0119 } 0120 break; 0121 0122 case 'returnresponse': 0123 $front->returnResponse((bool) $value); 0124 break; 0125 0126 case 'throwexceptions': 0127 $front->throwExceptions((bool) $value); 0128 break; 0129 0130 case 'actionhelperpaths': 0131 if (is_array($value)) { 0132 foreach ($value as $helperPrefix => $helperPath) { 0133 Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix); 0134 } 0135 } 0136 break; 0137 0138 case 'dispatcher': 0139 if (!isset($value['class'])) { 0140 // require_once 'Zend/Application/Exception.php'; 0141 throw new Zend_Application_Exception('You must specify both '); 0142 } 0143 if (!isset($value['params'])) { 0144 $value['params'] = array(); 0145 } 0146 0147 $dispatchClass = $value['class']; 0148 if (!class_exists($dispatchClass)) { 0149 // require_once 'Zend/Application/Exception.php'; 0150 throw new Zend_Application_Exception('Dispatcher class not found!'); 0151 } 0152 $front->setDispatcher(new $dispatchClass((array)$value['params'])); 0153 break; 0154 default: 0155 $front->setParam($key, $value); 0156 break; 0157 } 0158 } 0159 0160 if (null !== ($bootstrap = $this->getBootstrap())) { 0161 $this->getBootstrap()->frontController = $front; 0162 } 0163 0164 return $front; 0165 } 0166 0167 /** 0168 * Retrieve front controller instance 0169 * 0170 * @return Zend_Controller_Front 0171 */ 0172 public function getFrontController() 0173 { 0174 if (null === $this->_front) { 0175 $this->_front = Zend_Controller_Front::getInstance(); 0176 } 0177 return $this->_front; 0178 } 0179 }