I'd like to run a Silex Application like this in Command Line:
$app = new Silex\Application();
$app->get('/hello/{name}', function($name) use($app) {
return 'Hello '.$app->escape($name);
});
$app->run();
I think for that purpose, i'd have to pass Symfony's Request Object as first parameter to the run method, but i've got no idea, where to set the Url-Path to make it work. Any Ideas? Or is there a better way to do this?
Here's a simple way to do it:
list($_, $method, $path) = $argv;
$request = Request::create($path, $method);
$app->run($request);
And then on the command line:
$ php console.php GET /
If you want to use silex in a command line, you need to use the Console Component, here a tutorial for silex: http://beryllium.ca/?p=481
Then you are able to call a twig (symfony) service, and to forward an action !
http://symfony.com/doc/current/cookbook/console/console_command.html#getting-services-from-the-service-container
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With