Download the PHP package kron0s/console-service-provider without Composer
On this page you can find all versions of the php package kron0s/console-service-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kron0s/console-service-provider
More information about kron0s/console-service-provider
Files in kron0s/console-service-provider
Package console-service-provider
Short Description console service provider for Silex
License MIT
Homepage http://knplabs.com
Informations about the package console-service-provider
ConsoleServiceProvider
Provides a Symfony\Component\Console
based console for Silex.
Install
Add knplabs/console-service-provider
to your composer.json
and register the service:
You can now copy the console
executable in whatever place you see fit, and tweak it to your needs. You will need a way to fetch your silex application, the most common way is to return it from your bootstrap:
For the rest of this document, we will assume you do have an app
directory, so the console
executable will be located at app/console
.
Usage
Use the console just like any Symfony\Component
based console:
Write commands
Your commands should extend Knp\Command\Command
to have access to the 2 useful following commands:
getSilexApplication
, which returns the silex applicationgetProjectDirectory
, which returns your project's root directory (as configured earlier)
I know, it's a lot to learn, but it's worth the pain.
Register commands
There are two ways of registering commands to the console application.
Directly access the console application from the console
executable
Open up app/console
, and stuff your commands directly into the console application:
Use the Event Dispatcher
This way is intended for use by provider developers and exposes an unobstrusive way to register commands in 3 simple steps:
- Register a listener to the
ConsoleEvents::INIT
event - ???
- PROFIT!
Example: