Bootstrap.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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-2009 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. * 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-2009 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 void
  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. $front->dispatch();
  91. }
  92. /**
  93. * Set module resource loader
  94. *
  95. * @param Zend_Loader_Autoloader_Resource $loader
  96. * @return Zend_Application_Module_Bootstrap
  97. */
  98. public function setResourceLoader(Zend_Loader_Autoloader_Resource $loader)
  99. {
  100. $this->_resourceLoader = $loader;
  101. return $this;
  102. }
  103. /**
  104. * Retrieve module resource loader
  105. *
  106. * @return Zend_Loader_Autoloader_Resource
  107. */
  108. public function getResourceLoader()
  109. {
  110. if ((null === $this->_resourceLoader)
  111. && (false !== ($namespace = $this->getAppNamespace()))
  112. ) {
  113. $r = new ReflectionClass($this);
  114. $path = $r->getFileName();
  115. $this->setResourceLoader(new Zend_Application_Module_Autoloader(array(
  116. 'namespace' => $namespace,
  117. 'basePath' => dirname($path),
  118. )));
  119. }
  120. return $this->_resourceLoader;
  121. }
  122. /**
  123. * Get application namespace (used for module autoloading)
  124. *
  125. * @return string
  126. */
  127. public function getAppNamespace()
  128. {
  129. return $this->_appNamespace;
  130. }
  131. /**
  132. * Set application namespace (for module autoloading)
  133. *
  134. * @param string
  135. * @return Zend_Application_Bootstrap_Bootstrap
  136. */
  137. public function setAppNamespace($value)
  138. {
  139. $this->_appNamespace = (string) $value;
  140. return $this;
  141. }
  142. }