File indexing completed on 2024-05-26 06:02:44

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 Module
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @version    $Id$
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  */
0022 
0023 /**
0024  * @see Zend_Application_Bootstrap_Bootstrap
0025  */
0026 // require_once 'Zend/Application/Bootstrap/Bootstrap.php';
0027 
0028 /**
0029  * Base bootstrap class for modules
0030  *
0031  * @uses       Zend_Loader_Autoloader_Resource
0032  * @uses       Zend_Application_Bootstrap_Bootstrap
0033  * @category   Zend
0034  * @package    Zend_Application
0035  * @subpackage Module
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 abstract class Zend_Application_Module_Bootstrap
0040     extends Zend_Application_Bootstrap_Bootstrap
0041 {
0042     /**
0043      * Set this explicitly to reduce impact of determining module name
0044      * @var string
0045      */
0046     protected $_moduleName;
0047 
0048     /**
0049      * Constructor
0050      *
0051      * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
0052      */
0053     public function __construct($application)
0054     {
0055         $this->setApplication($application);
0056 
0057         // Use same plugin loader as parent bootstrap
0058         if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) {
0059             $this->setPluginLoader($application->getPluginLoader());
0060         }
0061 
0062         $key = strtolower($this->getModuleName());
0063         if ($application->hasOption($key)) {
0064             // Don't run via setOptions() to prevent duplicate initialization
0065             $this->setOptions($application->getOption($key));
0066         }
0067 
0068         if ($application->hasOption('resourceloader')) {
0069             $this->setOptions(array(
0070                 'resourceloader' => $application->getOption('resourceloader')
0071             ));
0072         }
0073         $this->initResourceLoader();
0074 
0075         // ZF-6545: ensure front controller resource is loaded
0076         if (!$this->hasPluginResource('FrontController')) {
0077             $this->registerPluginResource('FrontController');
0078         }
0079 
0080         // ZF-6545: prevent recursive registration of modules
0081         if ($this->hasPluginResource('modules')) {
0082             $this->unregisterPluginResource('modules');
0083         }
0084     }
0085 
0086     /**
0087      * Ensure resource loader is loaded
0088      *
0089      * @return void
0090      */
0091     public function initResourceLoader()
0092     {
0093         $this->getResourceLoader();
0094     }
0095 
0096     /**
0097      * Get default application namespace
0098      *
0099      * Proxies to {@link getModuleName()}, and returns the current module
0100      * name
0101      *
0102      * @return string
0103      */
0104     public function getAppNamespace()
0105     {
0106         return $this->getModuleName();
0107     }
0108 
0109     /**
0110      * Retrieve module name
0111      *
0112      * @return string
0113      */
0114     public function getModuleName()
0115     {
0116         if (empty($this->_moduleName)) {
0117             $class = get_class($this);
0118             if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) {
0119                 $prefix = $matches[1];
0120             } else {
0121                 $prefix = $class;
0122             }
0123             $this->_moduleName = $prefix;
0124         }
0125         return $this->_moduleName;
0126     }
0127 }