File indexing completed on 2025-01-26 05:29:16
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 Bootstrap 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_Bootstrap_BootstrapAbstract 0025 */ 0026 // require_once 'Zend/Application/Bootstrap/BootstrapAbstract.php'; 0027 0028 /** 0029 * Concrete base class for bootstrap classes 0030 * 0031 * Registers and utilizes Zend_Controller_Front by default. 0032 * 0033 * @uses Zend_Application_Bootstrap_Bootstrap 0034 * @category Zend 0035 * @package Zend_Application 0036 * @subpackage Bootstrap 0037 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0038 * @license http://framework.zend.com/license/new-bsd New BSD License 0039 */ 0040 class Zend_Application_Bootstrap_Bootstrap 0041 extends Zend_Application_Bootstrap_BootstrapAbstract 0042 { 0043 /** 0044 * Application resource namespace 0045 * @var false|string 0046 */ 0047 protected $_appNamespace = false; 0048 0049 /** 0050 * Application resource autoloader 0051 * @var Zend_Loader_Autoloader_Resource 0052 */ 0053 protected $_resourceLoader; 0054 0055 /** 0056 * Constructor 0057 * 0058 * Ensure FrontController resource is registered 0059 * 0060 * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application 0061 */ 0062 public function __construct($application) 0063 { 0064 parent::__construct($application); 0065 0066 if ($application->hasOption('resourceloader')) { 0067 $this->setOptions( 0068 array( 0069 'resourceloader' => $application->getOption( 0070 'resourceloader' 0071 ) 0072 ) 0073 ); 0074 } 0075 $this->getResourceLoader(); 0076 0077 if (!$this->hasPluginResource('FrontController')) { 0078 $this->registerPluginResource('FrontController'); 0079 } 0080 } 0081 0082 /** 0083 * Run the application 0084 * 0085 * Checks to see that we have a default controller directory. If not, an 0086 * exception is thrown. 0087 * 0088 * If so, it registers the bootstrap with the 'bootstrap' parameter of 0089 * the front controller, and dispatches the front controller. 0090 * 0091 * @return mixed 0092 * @throws Zend_Application_Bootstrap_Exception 0093 */ 0094 public function run() 0095 { 0096 $front = $this->getResource('FrontController'); 0097 $default = $front->getDefaultModule(); 0098 if (null === $front->getControllerDirectory($default)) { 0099 throw new Zend_Application_Bootstrap_Exception( 0100 'No default controller directory registered with front controller' 0101 ); 0102 } 0103 0104 $front->setParam('bootstrap', $this); 0105 $response = $front->dispatch(); 0106 if ($front->returnResponse()) { 0107 return $response; 0108 } 0109 } 0110 0111 /** 0112 * Set module resource loader 0113 * 0114 * @param Zend_Loader_Autoloader_Resource $loader 0115 * @return Zend_Application_Module_Bootstrap 0116 */ 0117 public function setResourceLoader(Zend_Loader_Autoloader_Resource $loader) 0118 { 0119 $this->_resourceLoader = $loader; 0120 return $this; 0121 } 0122 0123 /** 0124 * Retrieve module resource loader 0125 * 0126 * @return Zend_Loader_Autoloader_Resource 0127 */ 0128 public function getResourceLoader() 0129 { 0130 if ((null === $this->_resourceLoader) 0131 && (false !== ($namespace = $this->getAppNamespace())) 0132 ) { 0133 $r = new ReflectionClass($this); 0134 $path = $r->getFileName(); 0135 $this->setResourceLoader( 0136 new Zend_Application_Module_Autoloader( 0137 array( 0138 'namespace' => $namespace, 0139 'basePath' => dirname($path), 0140 ) 0141 ) 0142 ); 0143 } 0144 return $this->_resourceLoader; 0145 } 0146 0147 /** 0148 * Get application namespace (used for module autoloading) 0149 * 0150 * @return string 0151 */ 0152 public function getAppNamespace() 0153 { 0154 return $this->_appNamespace; 0155 } 0156 0157 /** 0158 * Set application namespace (for module autoloading) 0159 * 0160 * @param string 0161 * @return Zend_Application_Bootstrap_Bootstrap 0162 */ 0163 public function setAppNamespace($value) 0164 { 0165 $this->_appNamespace = (string) $value; 0166 return $this; 0167 } 0168 }