示例#1
0
 public function dispatch()
 {
     $requestModule = $this->request->module();
     $requestController = $this->request->controller();
     $requestAction = $this->request->action();
     $controllerName = $this->buildControllerName($requestController, $requestModule);
     if (!class_exists($controllerName)) {
         throw new \Rapid\Dispatcher\Exception('Controller not found: ' . $controllerName);
     }
     /**
      * @var \Rapid\Controller
      */
     $controller = new $controllerName($this, $this->request);
     $action = $this->processActionName($requestAction);
     if (!method_exists($controller, $action)) {
         throw new \Rapid\Dispatcher\Exception('Action not found');
     }
     $actionView = new \Rapid\View();
     $actionView->setFile($this->viewFile($requestModule, $requestController, $requestAction));
     $controller->setView($actionView);
     $controller->preDispatch();
     $output = $controller->process($action);
     $controller->postDispatch();
     if ($controller->useLayout()) {
         $layout = new \Rapid\View();
         $layout->setFile($this->layoutFile($controller->layout()));
         $layout->setVariables((array) $controller->layoutVariables());
         $layout->setVariable('content', $output);
         $output = $layout->render();
     }
     echo $output;
 }
示例#2
0
 protected function setRequestValues(\Rapid\Request $request)
 {
     $request->setModule($this->moduleName())->setController($this->controllerName())->setAction($this->actionName());
     foreach ($this->additionalParams() as $key => $value) {
         $request->setParam($key, $value);
     }
 }
示例#3
0
 protected function processQuery()
 {
     if (!$this->request->query()) {
         return;
     }
     $paramsMaxIndex = count($this->request->params());
     foreach (explode('&', $this->request->query()) as $keyValuePair) {
         if (strpos($keyValuePair, '=') !== false) {
             list($key, $value) = explode('=', $keyValuePair);
         } else {
             $key = $paramsMaxIndex++;
             $value = $keyValuePair;
         }
         $this->request->setParam($key, $value);
     }
 }
示例#4
0
 public function testAction()
 {
     $this->assertEquals(null, $this->request->action(), 'Action is not null');
     $this->request->setAction('new');
     $this->assertEquals('new', $this->request->action(), 'Action is not "new"');
 }
示例#5
0
 public function testIsPost()
 {
     $_SERVER = array('REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/blog/');
     $request = new \Rapid\Request();
     $this->assertEquals($request->isPost(), true);
 }