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; }
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); } }
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); } }
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"'); }
public function testIsPost() { $_SERVER = array('REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/blog/'); $request = new \Rapid\Request(); $this->assertEquals($request->isPost(), true); }