/** * Routes the request the handler most appropriate. * * @return void */ protected function routeRequest() { $match = $this->router->match($this->api->resources, $this->request->getMethod(), $this->request->getPathInfo()); switch ($match->status) { case Router::FOUND: $this->routeToHandlers($match); break; case Router::NOT_FOUND: $this->routeToNotFound(); break; case Router::METHOD_NOT_ALLOWED: $this->routeToNotAllowed($match); break; } }
/** * This method can be used to give a significant performance boost to your * application by pre-generating and caching the routing table. Note that * this caching is NOT performed automatically and that the $api->cacheFile * property needs to be set to a writable path for this to succeed. * * @see cacheFile * @return void */ public function createCache() { $cache = new Cache($this->cacheFile); $router = new Router($cache, new UrlTools()); $table = $router->getRoutingTable($this->resources); $cache->set("router", $table); }
function testMethodNotAllowedMatch() { $this->cache->get("router")->shouldBeCalled()->willReturn(TestResource::expectedTable()); $router = new Router($this->cache->reveal(), new UrlTools()); $resources = array(__NAMESPACE__ . "\\TestResource"); $match = $router->match($resources, "POST", "/this/is/static"); $this->assertEquals(Router::METHOD_NOT_ALLOWED, $match->status, "Match"); $this->assertEquals(array("GET"), $match->allowed, "Allowed"); }