Bootstrap.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Module
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id$
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * @see Zend_Application_Bootstrap_Bootstrap
  24. */
  25. require_once 'Zend/Application/Bootstrap/Bootstrap.php';
  26. /**
  27. * Base bootstrap class for modules
  28. *
  29. * @uses Zend_Loader_Autoloader_Resource
  30. * @uses Zend_Application_Bootstrap_Bootstrap
  31. * @category Zend
  32. * @package Zend_Application
  33. * @subpackage Module
  34. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. abstract class Zend_Application_Module_Bootstrap
  38. extends Zend_Application_Bootstrap_Bootstrap
  39. {
  40. /**
  41. * Set this explicitly to reduce impact of determining module name
  42. * @var string
  43. */
  44. protected $_moduleName;
  45. /**
  46. * Constructor
  47. *
  48. * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
  49. * @return void
  50. */
  51. public function __construct($application)
  52. {
  53. $this->setApplication($application);
  54. // Use same plugin loader as parent bootstrap
  55. if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) {
  56. $this->setPluginLoader($application->getPluginLoader());
  57. }
  58. $key = strtolower($this->getModuleName());
  59. if ($application->hasOption($key)) {
  60. // Don't run via setOptions() to prevent duplicate initialization
  61. $this->setOptions($application->getOption($key));
  62. }
  63. if ($application->hasOption('resourceloader')) {
  64. $this->setOptions(array(
  65. 'resourceloader' => $application->getOption('resourceloader')
  66. ));
  67. }
  68. $this->initResourceLoader();
  69. // ZF-6545: ensure front controller resource is loaded
  70. if (!$this->hasPluginResource('FrontController')) {
  71. $this->registerPluginResource('FrontController');
  72. }
  73. // ZF-6545: prevent recursive registration of modules
  74. if ($this->hasPluginResource('modules')) {
  75. $this->unregisterPluginResource('modules');
  76. }
  77. }
  78. /**
  79. * Ensure resource loader is loaded
  80. *
  81. * @return void
  82. */
  83. public function initResourceLoader()
  84. {
  85. $this->getResourceLoader();
  86. }
  87. /**
  88. * Get default application namespace
  89. *
  90. * Proxies to {@link getModuleName()}, and returns the current module
  91. * name
  92. *
  93. * @return string
  94. */
  95. public function getAppNamespace()
  96. {
  97. return $this->getModuleName();
  98. }
  99. /**
  100. * Retrieve module name
  101. *
  102. * @return string
  103. */
  104. public function getModuleName()
  105. {
  106. if (empty($this->_moduleName)) {
  107. $class = get_class($this);
  108. if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) {
  109. $prefix = $matches[1];
  110. } else {
  111. $prefix = $class;
  112. }
  113. $this->_moduleName = $prefix;
  114. }
  115. return $this->_moduleName;
  116. }
  117. }