public function test_action_gets_transformed_to_array() { $route = new Route(['GET'], '/', function () { }); $this->assertTrue(is_array($route->action())); $this->assertTrue(isset($route->action()['uses'])); $this->assertTrue(is_callable($route->action()['uses'])); $route = new Route(['GET'], '/', 'HomeController@index'); $this->assertTrue(is_array($route->action())); $this->assertTrue(isset($route->action()['uses'])); $this->assertEquals('HomeController@index', $route->action()['uses']); $route = new Route(['GET'], '/', ['uses' => 'HomeController@index']); $this->assertTrue(is_array($route->action())); $this->assertTrue(isset($route->action()['uses'])); $this->assertEquals('HomeController@index', $route->action()['uses']); }
/** * 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); }
/** * @param Route $route * * @return bool */ public function isSatisfiedBy(Route $route) { $action = $route->action(); return is_callable($action['uses']); }