Slide 55
Slide 55 text
class RouteBuilder
{
private $index = 0;
private $routes;
public function __construct(RouteCollection $routes)
{
$this->routes = $routes;
}
public function get($path, $controller)
{
return $this->match($path, $controller, 'GET');
}
...
public function match($path, $controller, $method = null)
{
$name = $this->index++;
$requirements = $method ? ['_method' => $method] : [];
$route = new Route($path, ['_controller' => $controller], $requirements);
$this->routes->add($name, $route);
return $route;
}
}