/zf/library/Zend/Application/Bootstrap/Bootstrap.php

http://github.com/eryx/php-framework-benchmark · PHP · 156 lines · 63 code · 11 blank · 82 comment · 6 complexity · d4d6dc0995a9da8a3e7f44f73112352b MD5 · raw file

  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 Bootstrap
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Bootstrap.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * Concrete base class for bootstrap classes
  24. *
  25. * Registers and utilizes Zend_Controller_Front by default.
  26. *
  27. * @uses Zend_Application_Bootstrap_Bootstrap
  28. * @category Zend
  29. * @package Zend_Application
  30. * @subpackage Bootstrap
  31. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Application_Bootstrap_Bootstrap
  35. extends Zend_Application_Bootstrap_BootstrapAbstract
  36. {
  37. /**
  38. * Application resource namespace
  39. * @var false|string
  40. */
  41. protected $_appNamespace = false;
  42. /**
  43. * Application resource autoloader
  44. * @var Zend_Loader_Autoloader_Resource
  45. */
  46. protected $_resourceLoader;
  47. /**
  48. * Constructor
  49. *
  50. * Ensure FrontController resource is registered
  51. *
  52. * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
  53. * @return void
  54. */
  55. public function __construct($application)
  56. {
  57. parent::__construct($application);
  58. if ($application->hasOption('resourceloader')) {
  59. $this->setOptions(array(
  60. 'resourceloader' => $application->getOption('resourceloader')
  61. ));
  62. }
  63. $this->getResourceLoader();
  64. if (!$this->hasPluginResource('FrontController')) {
  65. $this->registerPluginResource('FrontController');
  66. }
  67. }
  68. /**
  69. * Run the application
  70. *
  71. * Checks to see that we have a default controller directory. If not, an
  72. * exception is thrown.
  73. *
  74. * If so, it registers the bootstrap with the 'bootstrap' parameter of
  75. * the front controller, and dispatches the front controller.
  76. *
  77. * @return mixed
  78. * @throws Zend_Application_Bootstrap_Exception
  79. */
  80. public function run()
  81. {
  82. $front = $this->getResource('FrontController');
  83. $default = $front->getDefaultModule();
  84. if (null === $front->getControllerDirectory($default)) {
  85. throw new Zend_Application_Bootstrap_Exception(
  86. 'No default controller directory registered with front controller'
  87. );
  88. }
  89. $front->setParam('bootstrap', $this);
  90. $response = $front->dispatch();
  91. if ($front->returnResponse()) {
  92. return $response;
  93. }
  94. }
  95. /**
  96. * Set module resource loader
  97. *
  98. * @param Zend_Loader_Autoloader_Resource $loader
  99. * @return Zend_Application_Module_Bootstrap
  100. */
  101. public function setResourceLoader(Zend_Loader_Autoloader_Resource $loader)
  102. {
  103. $this->_resourceLoader = $loader;
  104. return $this;
  105. }
  106. /**
  107. * Retrieve module resource loader
  108. *
  109. * @return Zend_Loader_Autoloader_Resource
  110. */
  111. public function getResourceLoader()
  112. {
  113. if ((null === $this->_resourceLoader)
  114. && (false !== ($namespace = $this->getAppNamespace()))
  115. ) {
  116. $r = new ReflectionClass($this);
  117. $path = $r->getFileName();
  118. $this->setResourceLoader(new Zend_Application_Module_Autoloader(array(
  119. 'namespace' => $namespace,
  120. 'basePath' => dirname($path),
  121. )));
  122. }
  123. return $this->_resourceLoader;
  124. }
  125. /**
  126. * Get application namespace (used for module autoloading)
  127. *
  128. * @return string
  129. */
  130. public function getAppNamespace()
  131. {
  132. return $this->_appNamespace;
  133. }
  134. /**
  135. * Set application namespace (for module autoloading)
  136. *
  137. * @param string
  138. * @return Zend_Application_Bootstrap_Bootstrap
  139. */
  140. public function setAppNamespace($value)
  141. {
  142. $this->_appNamespace = (string) $value;
  143. return $this;
  144. }
  145. }