public function testAddParam() { $this->markTestSkipped("Check if is request test"); $this->object->explode("/index/index"); $this->object->addParams(array("hello" => "ciao")); $this->object->addParams(array("bella" => 'zi')); $p = $this->object->getParams(); $this->assertEquals(2, count($p)); $this->assertEquals("ciao", $p["hello"]); $this->assertEquals("zi", $p["bella"]); }
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()); }