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