added route task.
This commit is contained in:
parent
10ee41f3b3
commit
baac975fc6
|
@ -46,6 +46,16 @@
|
||||||
return new Tasks\Session\Manager;
|
return new Tasks\Session\Manager;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The route task is responsible for calling routes within the
|
||||||
|
* application and dumping the result. This allows for simple
|
||||||
|
* testing of APIs and JSON based applications.
|
||||||
|
*/
|
||||||
|
IoC::singleton('task: route', function()
|
||||||
|
{
|
||||||
|
return new Tasks\Route;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "test" task is responsible for running the unit tests for
|
* The "test" task is responsible for running the unit tests for
|
||||||
* the application, bundles, and the core framework itself.
|
* the application, bundles, and the core framework itself.
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php namespace Laravel\CLI\Tasks;
|
||||||
|
|
||||||
|
use Laravel\URI;
|
||||||
|
use Laravel\Request;
|
||||||
|
use Laravel\Routing\Router;
|
||||||
|
|
||||||
|
class Route extends Task {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a route and dump the result.
|
||||||
|
*
|
||||||
|
* @param array $arguments
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run($arguments = array())
|
||||||
|
{
|
||||||
|
if ( ! count($arguments) == 2)
|
||||||
|
{
|
||||||
|
throw new \Exception("Please specify a request method and URI.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// First we'll set the request method and URI in the $_SERVER array,
|
||||||
|
// which will allow the framework to retrieve the proper method
|
||||||
|
// and URI using the normal URI and Request classes.
|
||||||
|
$_SERVER['REQUEST_METHOD'] = strtoupper($arguments[0]);
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_URI'] = $arguments[1];
|
||||||
|
|
||||||
|
$this->route();
|
||||||
|
|
||||||
|
echo PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dump the results of the currently established route.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function route()
|
||||||
|
{
|
||||||
|
// We'll call the router using the method and URI specified by
|
||||||
|
// the developer on the CLI. If a route is found, we will not
|
||||||
|
// run the filters, but simply dump the result.
|
||||||
|
$route = Router::route(Request::method(), URI::current());
|
||||||
|
|
||||||
|
if ( ! is_null($route))
|
||||||
|
{
|
||||||
|
var_dump($route->response());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo '404: Not Found';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue