/** * Dispatch the request * * @param Route $route * * @return mixed */ public function dispatch(Route $route) { $action = $route->action(); $callback = $action['uses']; $parameters = $this->resolver->resolve(new ReflectionFunction($callback), $route->parameters()); return call_user_func_array($callback, $parameters); }
/** * Dispatch the request * * @param Route $route * * @throws NotFoundHttpException * @return mixed */ public function dispatch(Route $route) { $action = $route->action(); list($class, $method) = explode('@', $action['uses']); if (!method_exists($instance = $this->container->make($class), $method)) { throw new NotFoundHttpException(); } $parameters = $this->resolver->resolve(new ReflectionMethod($instance, $method), $route->parameters()); return $this->container->call([$instance, $method], $parameters); }
public function test_can_bind_parameters_to_route() { $route = new Route(['GET'], '{id}', 'HomeController@index'); $route->bind(['id' => 1]); $this->assertEquals(['id' => 1], $route->parameters()); }