web/lib/Zend/Application/Resource/Frontcontroller.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 Resource
       
    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: Frontcontroller.php 23378 2010-11-18 21:48:27Z bittarman $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Application_Resource_ResourceAbstract
       
    25  */
       
    26 require_once 'Zend/Application/Resource/ResourceAbstract.php';
       
    27 
       
    28 
       
    29 /**
       
    30  * Front Controller resource
       
    31  *
       
    32  * @category   Zend
       
    33  * @package    Zend_Application
       
    34  * @subpackage Resource
       
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    37  */
       
    38 class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
       
    39 {
       
    40     /**
       
    41      * @var Zend_Controller_Front
       
    42      */
       
    43     protected $_front;
       
    44 
       
    45     /**
       
    46      * Initialize Front Controller
       
    47      *
       
    48      * @return Zend_Controller_Front
       
    49      */
       
    50     public function init()
       
    51     {
       
    52         $front = $this->getFrontController();
       
    53 
       
    54         foreach ($this->getOptions() as $key => $value) {
       
    55             switch (strtolower($key)) {
       
    56                 case 'controllerdirectory':
       
    57                     if (is_string($value)) {
       
    58                         $front->setControllerDirectory($value);
       
    59                     } elseif (is_array($value)) {
       
    60                         foreach ($value as $module => $directory) {
       
    61                             $front->addControllerDirectory($directory, $module);
       
    62                         }
       
    63                     }
       
    64                     break;
       
    65 
       
    66                 case 'modulecontrollerdirectoryname':
       
    67                     $front->setModuleControllerDirectoryName($value);
       
    68                     break;
       
    69 
       
    70                 case 'moduledirectory':
       
    71                     if (is_string($value)) {
       
    72                         $front->addModuleDirectory($value);
       
    73                     } elseif (is_array($value)) {
       
    74                         foreach($value as $moduleDir) {
       
    75                             $front->addModuleDirectory($moduleDir);
       
    76                         }
       
    77                     }
       
    78                     break;
       
    79 
       
    80                 case 'defaultcontrollername':
       
    81                     $front->setDefaultControllerName($value);
       
    82                     break;
       
    83 
       
    84                 case 'defaultaction':
       
    85                     $front->setDefaultAction($value);
       
    86                     break;
       
    87 
       
    88                 case 'defaultmodule':
       
    89                     $front->setDefaultModule($value);
       
    90                     break;
       
    91 
       
    92                 case 'baseurl':
       
    93                     if (!empty($value)) {
       
    94                         $front->setBaseUrl($value);
       
    95                     }
       
    96                     break;
       
    97 
       
    98                 case 'params':
       
    99                     $front->setParams($value);
       
   100                     break;
       
   101 
       
   102                 case 'plugins':
       
   103                     foreach ((array) $value as $pluginClass) {
       
   104                     	$stackIndex = null;
       
   105                     	if(is_array($pluginClass)) {
       
   106                     	    $pluginClass = array_change_key_case($pluginClass, CASE_LOWER);
       
   107                             if(isset($pluginClass['class']))
       
   108                             {
       
   109                                 if(isset($pluginClass['stackindex'])) {
       
   110                                     $stackIndex = $pluginClass['stackindex'];
       
   111                                 }
       
   112 
       
   113                                 $pluginClass = $pluginClass['class'];
       
   114                             }
       
   115                         }
       
   116 
       
   117                         $plugin = new $pluginClass();
       
   118                         $front->registerPlugin($plugin, $stackIndex);
       
   119                     }
       
   120                     break;
       
   121 
       
   122                 case 'returnresponse':
       
   123                     $front->returnResponse((bool) $value);
       
   124                     break;
       
   125 
       
   126                 case 'throwexceptions':
       
   127                     $front->throwExceptions((bool) $value);
       
   128                     break;
       
   129 
       
   130                 case 'actionhelperpaths':
       
   131                     if (is_array($value)) {
       
   132                         foreach ($value as $helperPrefix => $helperPath) {
       
   133                             Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
       
   134                         }
       
   135                     }
       
   136                     break;
       
   137 
       
   138                 default:
       
   139                     $front->setParam($key, $value);
       
   140                     break;
       
   141             }
       
   142         }
       
   143 
       
   144         if (null !== ($bootstrap = $this->getBootstrap())) {
       
   145             $this->getBootstrap()->frontController = $front;
       
   146         }
       
   147 
       
   148         return $front;
       
   149     }
       
   150 
       
   151     /**
       
   152      * Retrieve front controller instance
       
   153      *
       
   154      * @return Zend_Controller_Front
       
   155      */
       
   156     public function getFrontController()
       
   157     {
       
   158         if (null === $this->_front) {
       
   159             $this->_front = Zend_Controller_Front::getInstance();
       
   160         }
       
   161         return $this->_front;
       
   162     }
       
   163 }