Provides a Symfony\Component\Console
based console for Silex 2.
$ composer require keiii/console-service-provider
#!/usr/bin/env php
<?php
$app = new Application();
$app->register(new ConsoleServiceProvider(), array(
'console.name' => 'MyApplication',
'console.version' => '1.0.0',
));
$console = $app['console'];
$console->add(new MyCommand());
$console->run();
Your commands should extend KEIII\SilexConsole\Command
to have access getSilexApplication
, which returns the silex application.
Use the console just like any Symfony\Component
based console:
$ app/console my:command
<?php
$app['logger'] = $app::share(function () {
return new MyLogger(); // \Psr\Log\LoggerInterface
});
$app['console.log.listener'] = $app::share(function (Application $app) {
return new \KEIII\SilexConsole\ConsoleLogListener($app['logger']);
});
$app['dispatcher']->addSubscriber($app['console.log.listener']);