Commit c621e23a authored by Kris Wallsmith's avatar Kris Wallsmith Committed by Fabien Potencier

Added support for RESTful routes.

parent ab1f17b6
...@@ -11,12 +11,22 @@ $hello = function ($name) ...@@ -11,12 +11,22 @@ $hello = function ($name)
return new Response('Hello '.$name); return new Response('Hello '.$name);
}; };
$goodbye = function($name)
{
return new Response('Goodbye '.$name);
};
$framework = new Framework(array( $framework = new Framework(array(
'/hello/:name' => $hello, 'GET /hello/:name' => $hello,
'POST /goodbye/:name' => $goodbye,
)); ));
// Simulate a request without a Client // Simulate a hello request without a Client
//$request = Request::create('/hello/Fabien'); //$request = Request::create('/hello/Fabien');
//$framework->handle($request)->send(); //$framework->handle($request)->send();
// Simulate a goodbye request without a Client
//$request = Request::create('/goodbye/Fabien', 'post');
//$framework->handle($request)->send();
$framework->handle()->send(); $framework->handle()->send();
No preview for this file type
...@@ -32,7 +32,13 @@ class Framework extends HttpKernel ...@@ -32,7 +32,13 @@ class Framework extends HttpKernel
{ {
$this->routes = new RouteCollection(); $this->routes = new RouteCollection();
foreach ($map as $pattern => $to) { foreach ($map as $pattern => $to) {
$route = new Route($pattern, array('_controller' => $to)); if (false !== strpos($pattern, ' ')) {
list($method, $pattern) = explode(' ', $pattern, 2);
} else {
$method = 'GET';
}
$route = new Route($pattern, array('_controller' => $to), array('_method' => explode('|', $method)));
$this->routes->addRoute(str_replace(array('/', ':'), '_', $pattern), $route); $this->routes->addRoute(str_replace(array('/', ':'), '_', $pattern), $route);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment