Bootstrap.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-2015 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-2015 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. */
  50. public function __construct($application)
  51. {
  52. $this->setApplication($application);
  53. // Use same plugin loader as parent bootstrap
  54. if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) {
  55. $this->setPluginLoader($application->getPluginLoader());
  56. }
  57. $key = strtolower($this->getModuleName());
  58. if ($application->hasOption($key)) {
  59. // Don't run via setOptions() to prevent duplicate initialization
  60. $this->setOptions($application->getOption($key));
  61. }
  62. if ($application->hasOption('resourceloader')) {
  63. $this->setOptions(array(
  64. 'resourceloader' => $application->getOption('resourceloader')
  65. ));
  66. }
  67. $this->initResourceLoader();
  68. // ZF-6545: ensure front controller resource is loaded
  69. if (!$this->hasPluginResource('FrontController')) {
  70. $this->registerPluginResource('FrontController');
  71. }
  72. // ZF-6545: prevent recursive registration of modules
  73. if ($this->hasPluginResource('modules')) {
  74. $this->unregisterPluginResource('modules');
  75. }
  76. }
  77. /**
  78. * Ensure resource loader is loaded
  79. *
  80. * @return void
  81. */
  82. public function initResourceLoader()
  83. {
  84. $this->getResourceLoader();
  85. }
  86. /**
  87. * Get default application namespace
  88. *
  89. * Proxies to {@link getModuleName()}, and returns the current module
  90. * name
  91. *
  92. * @return string
  93. */
  94. public function getAppNamespace()
  95. {
  96. return $this->getModuleName();
  97. }
  98. /**
  99. * Retrieve module name
  100. *
  101. * @return string
  102. */
  103. public function getModuleName()
  104. {
  105. if (empty($this->_moduleName)) {
  106. $class = get_class($this);
  107. if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) {
  108. $prefix = $matches[1];
  109. } else {
  110. $prefix = $class;
  111. }
  112. $this->_moduleName = $prefix;
  113. }
  114. return $this->_moduleName;
  115. }
  116. }