/** * Route should set name and be cached by Router */ public function testRouteSetsNameAndIsCached() { $router = new RouterMock(); $route = new Slim_Route('/foo/bar', function () {}); $route->setRouter($router); $route->name('foo'); $cacheKeys = array_keys($router->cache); $cacheValues = array_values($router->cache); $this->assertEquals($cacheKeys[0], 'foo'); $this->assertSame($cacheValues[0], $route); }
/** * Map a route to a callback function * @param string $pattern The URL pattern (ie. "/books/:id") * @param mixed $callable Anything that returns TRUE for is_callable() * @return Slim_Route */ public function map($pattern, $callable) { $route = new Slim_Route($pattern, $callable); $route->setRouter($this); $this->routes[] = $route; return $route; }
public function testDispatchWithoutCallable() { Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/hello/josh', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim')); $env = Slim_Environment::getInstance(); $req = new Slim_Http_Request($env); $res = new Slim_Http_Response(); $router = new Slim_Router($req, $res); $route = new Slim_Route('/hello/:name', 'foo'); $route->setRouter($router); $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI $this->assertFalse($route->dispatch()); }
/** * Map a route to a callback function * * @param string $pattern The URL pattern (ie. "/books/:id") * @param mixed $callable Anything that returns TRUE for is_callable() * @param string $method The HTTP request method (GET, POST, PUT, DELETE) * @return Route */ public function map($pattern, $callable, $method) { $route = new Slim_Route($pattern, $callable); $route->setRouter($this); $methodKey = $method === Slim_Http_Request::METHOD_HEAD ? Slim_Http_Request::METHOD_GET : $method; $this->routes[$methodKey][] = $route; return $route; }