ConsoleServiceProvider
ConsoleServiceProvider copied to clipboard
Commands as a Service with Symfony Console in Silex
Console Service Provider for Silex
The ConsoleServiceProvider enable Symfony Console in Silex make easy to register command from any other service provider.
Parameters
- console.name (optional): The name of your application.
- console.version (optional): The version of your application.
Services
- console: The Console Application. Use
$app['console']->run().
Registering
Installation:
- Use the official Git repository (https://github.com/LExpress/ConsoleServiceProvider);
- Install it via Composer (lexpress/console-service-provider on Packagist).
Register the service provider in your Silex application.
$app->register(new LExpress\Silex\ConsoleServiceProvider(), array(
'console.name' => 'Wahou',
'console.version' => '1.0',
));
Register commands
Services named with command.* are automatically registered to the console.
$app['command.propel.model.build'] = $app->share(function ($app) {
return new Propel\Generator\Command\ModelBuildCommand();
});
Running the console application
The Console Application is available in your Silex Application with the service alias console.
To run it, you can create an executable file in your project.
#!/usr/bin/env php
<?php
// Load the class loader
require __DIR__.'/vendor/autoload.php';
// Initialize your application with the ConsoleServiceProvider
$app = require __DIR__.'/app.php';
// Run the console with the default input/output
$app['console']->run();
License
ConsoleServiceProvider is licensed under the MIT license.