示例#1
0
 /**
  * Initialize Front Controller
  *
  * @return \Zend\Controller\Front
  */
 public function init()
 {
     $front = $this->getFrontController();
     foreach ($this->getOptions() as $key => $value) {
         switch (strtolower($key)) {
             case 'controllerdirectory':
                 if (is_string($value)) {
                     $front->setControllerDirectory($value);
                 } elseif (is_array($value)) {
                     foreach ($value as $module => $directory) {
                         $front->addControllerDirectory($directory, $module);
                     }
                 }
                 break;
             case 'modulecontrollerdirectoryname':
                 $front->setModuleControllerDirectoryName($value);
                 break;
             case 'moduledirectory':
                 $front->addModuleDirectory($value);
                 break;
             case 'defaultcontrollername':
                 $front->setDefaultControllerName($value);
                 break;
             case 'defaultaction':
                 $front->setDefaultAction($value);
                 break;
             case 'defaultmodule':
                 $front->setDefaultModule($value);
                 break;
             case 'baseurl':
                 if (!empty($value)) {
                     $front->setBaseUrl($value);
                 }
                 break;
             case 'params':
                 $front->setParams($value);
                 break;
             case 'plugins':
                 foreach ((array) $value as $pluginClass) {
                     $stackIndex = null;
                     if (is_array($pluginClass)) {
                         $pluginClass = array_change_key_case($pluginClass, CASE_LOWER);
                         if (isset($pluginClass['class'])) {
                             if (isset($pluginClass['stackindex'])) {
                                 $stackIndex = $pluginClass['stackindex'];
                             }
                             $pluginClass = $pluginClass['class'];
                         }
                     }
                     $plugin = new $pluginClass();
                     $front->registerPlugin($plugin, $stackIndex);
                 }
                 break;
             case 'returnresponse':
                 $front->returnResponse((bool) $value);
                 break;
             case 'throwexceptions':
                 $front->throwExceptions((bool) $value);
                 break;
             case 'actionhelperpaths':
                 if (is_array($value)) {
                     foreach ($value as $helperPrefix => $helperPath) {
                         \Zend\Controller\Action\HelperBroker::addPath($helperPath, $helperPrefix);
                     }
                 }
                 break;
             default:
                 $front->setParam($key, $value);
                 break;
         }
     }
     if (null !== ($bootstrap = $this->getBootstrap())) {
         $this->getBootstrap()->frontController = $front;
     }
     return $front;
 }
示例#2
0
 public function testHelperPathStackIsLifo()
 {
     HelperBroker::addPath(dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Helpers', 'MyApp');
     $urlHelper = HelperBroker::getStaticHelper('url');
     $this->assertTrue($urlHelper instanceof \MyApp\Url);
 }