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