當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dispatcher::setRequest方法代碼示例

本文整理匯總了PHP中Dispatcher::setRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::setRequest方法的具體用法?PHP Dispatcher::setRequest怎麽用?PHP Dispatcher::setRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dispatcher的用法示例。


在下文中一共展示了Dispatcher::setRequest方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: initialize

 protected function initialize()
 {
     $arrConf = Loader::getInstance()->getConfig();
     if ($arrConf) {
         //初始化插件列表
         if (isset($arrConf['plugins'])) {
             foreach ($arrConf['plugins'] as $p) {
                 $plugin = new $p();
                 $this->_dispatcher->addPlugin($plugin);
             }
         }
         //初始化請求類
         if (isset($arrConf['request_class']) && $arrConf['request_class']) {
             $request = new $arrConf['request_class']();
             $this->_dispatcher->setRequest($request);
         }
         //初始化響應類
         if (isset($arrConf['response_class']) && $arrConf['response_class']) {
             $response = new $arrConf['response_class']();
             $this->_dispatcher->setResponse($response);
         }
         //初始化試圖類
         if (isset($arrConf['view_class']) && $arrConf['view_class']) {
             $view = new $arrConf['view_class']();
             $this->_dispatcher->setView($view);
         }
         if (isset($arrConf['enable_debug']) && $arrConf['enable_debug']) {
             $this->setDebugEnabled(true);
         }
     }
 }
開發者ID:zhxia,項目名稱:nspf,代碼行數:31,代碼來源:Application.php

示例2: dispatch

 public function dispatch(Route $route)
 {
     $protoView = $this->getBootstrap()->getResource("view") ? $this->getBootstrap()->getResource("view") : new View();
     $controllerPath = $this->getControllerPath();
     $router = $this->_router;
     $request = $this->_request;
     $protoView->addHelper("pull", function ($uri) use($controllerPath, $router, $request) {
         $request = clone $request;
         $request->setUri($uri);
         $routeObj = $router->match($request);
         $controllerClassName = $routeObj->getControllerName() . "Controller";
         $action = $routeObj->getActionName() . "Action";
         $classPath = realpath($controllerPath . DIRECTORY_SEPARATOR . $controllerClassName . ".php");
         if (file_exists($classPath)) {
             require_once $classPath;
             $controller = new $controllerClassName();
             $controller->setParams($routeObj->getParams());
             if (method_exists($controller, $action)) {
                 ob_start();
                 $controller->init();
                 $data = $controller->{$action}();
                 ob_end_clean();
                 return $data;
             } else {
                 throw new RuntimeException("Pull operation {$routeObj->getControllerName()} - {$routeObj->getActionName()} failed.", 404);
             }
         } else {
             throw new RuntimeException("Pull operation {$routeObj->getControllerName()} - {$routeObj->getActionName()} failed.", 404);
         }
     });
     $dispatcher = new Dispatcher($protoView);
     $dispatcher->setRouter($this->_router);
     $dispatcher->setRequest($this->_request);
     $dispatcher->setEventManager($this->getEventManager());
     $dispatcher->setBootstrap($this->_bootstrap);
     $dispatcher->setControllerPath($this->getControllerPath());
     try {
         $this->_page = $dispatcher->dispatch($route);
     } catch (Exception $e) {
         $errorRoute = new Route();
         $errorRoute->addParams(array('exception' => $e));
         $dispatcher->clearHeaders();
         $dispatcher->addHeader("", "", 404);
         $errorRoute->setControllerName("error");
         $errorRoute->setActionName("error");
         $this->_page = $dispatcher->dispatch($errorRoute);
     }
     return array('headers' => $dispatcher->getHeaders());
 }
開發者ID:elvis2,項目名稱:simple-mvc,代碼行數:49,代碼來源:Application.php


注:本文中的Dispatcher::setRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。