Cilex/Cilex — pull request #28 by simensen (2012-11-21 18:33:44+00:00)
Title: [WIP] Use Cilex Pimple Console Service Provider

As discussed with @mvriel, I am working on extracting the Console service from Cilex itself into an external Pimple service provider that can be reused by any Pimple application (like Silex).

This PR removes the Console service creation from `Cilex\Application` and instead uses a standalone Console service provider. You can find that service provider [here](https://github.com/simensen/cilex-console-service-provider).

The intention is that the standalone Console service provider will fall under the Cilex namespace. Since it does not exist yet it is living under my account while I work on it. (@mvriel requested it be under \Cilex)

A few things...

I would like to propose migrating away from relying on `Cilex\Command\Command` as it would tie any commands based on it to Cilex. As this is all about reusability across the Pimple ecosystem, the sooner we are making Pimple things instead of Silex/Cilex/Whateverlex things, the better.

There is a mechanism for getting access to the underlying Pimple Container via `$this->getApplication()->getContainer()`, similar to how Symfony Framework Bundle is setup. This should make it trivial to port things like the Doctrine commands to the Pimple ecosystem in one go rather than having to do it for each project (Silex, Cilex, etc.).

Any command can now be registered to Cilex via `$app->command()`, even those that are not specifically made for Cilex.

The tests work and my sample application works as expected:

```php
command(new \Cilex\Command\GreetCommand());
$app->command(new \Cilex\Command\DemoInfoCommand());
$app->run();
```

In theory this should be BC with existing projects but I'm new to the Cilex ecosystem so I'm not sure exactly how people are using it.

For a service provider that wants to expose commands in a Pimple portable way, it can be done like this:

```php
share($app->extend('console', function($console, $app) {
$console->addCommand(new MyReusableCommand);

return $console;
}));
```

---

The background on this is that I've been trying to port some console commands from DoctrineBundle and DoctrineMigrationsBundle to Silex. I brought up the idea of a Console service provider and having a Silex specific subclass of Console Application as an RFC (here: fabpot/Silex#542).

Shortly after I started looking at Cilex and realized that Cilex was providing a `$app['console']` service more or less like I was proposing. I found @mvriel on IRC and proposed simply moving Cilex's Console service stuff to an external provider so that Cilex, Silex, and any Pimple based application could share the "Console as a service" functionality.