route.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php namespace Laravel\CLI\Tasks;
  2. use Laravel\URI;
  3. use Laravel\Request;
  4. use Laravel\Routing\Router;
  5. class Route extends Task {
  6. /**
  7. * Execute a route and dump the result.
  8. *
  9. * @param array $arguments
  10. * @return void
  11. */
  12. public function call($arguments = array())
  13. {
  14. if ( count($arguments) != 2)
  15. {
  16. throw new \Exception("Please specify a request method and URI.");
  17. }
  18. // First we'll set the request method and URI in the $_SERVER array,
  19. // which will allow the framework to retrieve the proper method
  20. // and URI using the URI and Request classes.
  21. $_SERVER['REQUEST_METHOD'] = strtoupper($arguments[0]);
  22. $_SERVER['REQUEST_URI'] = $arguments[1];
  23. $this->route();
  24. echo PHP_EOL;
  25. }
  26. /**
  27. * Dump the results of the currently established route.
  28. *
  29. * @return void
  30. */
  31. protected function route()
  32. {
  33. // We'll call the router using the method and URI specified by
  34. // the developer on the CLI. If a route is found, we will not
  35. // run the filters, but simply dump the result.
  36. $route = Router::route(Request::method(), $_SERVER['REQUEST_URI']);
  37. if ( ! is_null($route))
  38. {
  39. var_dump($route->response());
  40. }
  41. else
  42. {
  43. echo '404: Not Found';
  44. }
  45. }
  46. }