Skip to content

Commit

Permalink
Merge branch 'container-aware'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnugat committed Jan 25, 2016
2 parents 233e63d + fff2214 commit dad550d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

##

> **BC breaks**:
>
> * `Gnugat\MicroFrameworkBundle\Console\KernelApplication` has been
> moved to `Gnugat\MicroFrameworkBundle\Service\KernelApplication`
## 0.3.0: Console

* added support for `console.command` tag
Expand Down
16 changes: 15 additions & 1 deletion Console/KernelApplication.php → Service/KernelApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* file that was distributed with this source code.
*/

namespace Gnugat\MicroFrameworkBundle\Console;
namespace Gnugat\MicroFrameworkBundle\Service;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Kernel;

Expand Down Expand Up @@ -45,6 +47,18 @@ public function doRun(InputInterface $input, OutputInterface $output)
{
$this->kernel->boot();
$container = $this->kernel->getContainer();
$bundles = $this->kernel->getBundles();
foreach ($bundles as $bundle) {
if ($bundle instanceof Bundle) {
$bundle->registerCommands($this);
}
}
$commands = $this->all();
foreach ($commands as $command) {
if ($command instanceof ContainerAwareInterface) {
$command->setContainer($container);
}
}
if (true === $container->hasParameter('console.command.ids')) {
foreach ($container->getParameter('console.command.ids') as $id) {
$this->add($container->get($id));
Expand Down
17 changes: 16 additions & 1 deletion Tests/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Gnugat\MicroFrameworkBundle\Tests;

use Gnugat\MicroFrameworkBundle\Console\KernelApplication;
use Gnugat\MicroFrameworkBundle\Service\KernelApplication;
use Symfony\Component\Console\Tester\ApplicationTester;

class ConsoleTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -40,4 +40,19 @@ public function it_runs_commands()

self::assertSame(0, $statusCode, $this->app->getDisplay());
}

/**
* @test
*/
public function it_runs_container_aware_commands()
{
$input = array(
'say-hello-aware',
'name' => 'Igor',
);

$statusCode = $this->app->run($input);

self::assertSame(0, $statusCode, $this->app->getDisplay());
}
}
48 changes: 48 additions & 0 deletions Tests/CustomBundle/Command/SayHelloAwareCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the gnugat/micro-framework-bundle package.
*
* (c) Loïc Faugeron <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gnugat\MicroFrameworkBundle\Tests\CustomBundle\Command;

use Gnugat\MicroFrameworkBundle\Tests\CustomBundle\CommandBus\SayHello;
use League\Tactician\CommandBus;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;


class SayHelloAwareCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('say-hello-aware');
$this->addArgument('name', InputArgument::OPTIONAL, 'Who should we say hello to?', 'World');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = $this->container->get('tactician.commandBus')->handle(new SayHello(
$input->getArgument('name')
));

$output->writeln($message);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"symfony/config": "^3.0",
"symfony/console": "^3.0",
"symfony/dependency-injection": "^3.0",
"symfony/finder": "^3.0",
"symfony/http-kernel": "^3.0",
"symfony/routing": "^3.0"
},
Expand Down
10 changes: 6 additions & 4 deletions doc/01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ Next, the `framework` configuration key needs to be removed from `app/config/con

Finally, in the `bin/console` file
replace `Symfony\Bundle\FrameworkBundle\Console\Application`
with `Gnugat\MicroFrameworkBundle\Console\KernelApplication as Application`.
with `Gnugat\MicroFrameworkBundle\Service\KernelApplication as Application`.

## Standard Edition

The [Standard Edition](https://github.com/symfony/symfony-standard) provides some
pre-installed libraries:
There's an official distribution: [Standard Edition](https://github.com/symfony/symfony-standard).
It provides pre-installed libraries, but it can be installed in the same manner:

```
composer create-project symfony/framework-standard-edition
cd framework-standard-edition
composer require 'gnugat/micro-framework-bundle'
```

Then we need to clean `app/AppKernel.php` file by removing the bundles following:
Then we need to clean `app/AppKernel.php` file by removing the following bundles:

* `Symfony\Bundle\FrameworkBundle\FrameworkBundle`
* `Doctrine\Bundle\DoctrineBundle\DoctrineBundle` (depends on FrameworkBundle specific console Application)
* `Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle` (depends on annotations)
* `Symfony\Bundle\TwigBundle\TwigBundle` (depends on assets)
* `Symfony\Bundle\WebProfilerBundle\WebProfilerBundle` (depends on data collectors)
Expand All @@ -56,6 +57,7 @@ Don't forget to add `Gnugat\MicroFrameworkBundle\GnugatMicroFrameworkBundle`.
Next remove configuration for the following keys in `app/config/config*.yml`:

* `framework`
* `doctrine` (as well as `database_*` parameters)
* `web_profiler`
* `twig`

Expand Down
22 changes: 13 additions & 9 deletions doc/02-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ as well as how to fix it.
### Annotations

`MicroFrameworkBundle` doesn't provide support for annotations, but by manually
setting up we can still be compatible with bundles that use this configuration format:
setting it up bundles that use this configuration format can be used:

1. register an implementation of `Doctrine\Common\Annotations\Reader` as a service named `annotation_reader`
2. register `AnnotationLoader` for the related components (e.g. Validator, Routing, Serializer, etc)
Expand Down Expand Up @@ -84,8 +84,8 @@ not be able to be registered.
### Debug Toolbar and Profiler

The debug toolbar isn't embeded provided by `MicroFrameworkBundle` as it would
add a dependency on frontend tools.
The debug toolbar isn't provided by `MicroFrameworkBundle` as it would add a
dependency on frontend tools.

It is still possible to install it by registering `DataCollectors` as well as the
`Profiler`.
Expand All @@ -98,22 +98,26 @@ No extensions for HttpCache are provided and ESI/fragements are not registered.

### Console

`FrameworkBundle` prodives a `ContainerAwareCommand`. Any bundle providing
commands that extend it won't be compatible with `MicroFrameworkBundle`.
While bundles that have `Commands` extending `ContainerAwareCommand` still require
`FrameworkBundle`, they can be compatible with `MicroFrameworkBundle`.

We recommend to register those commands as services instead, as they will be
supported in the future by `MicroFrameworkBundle`.
> **Note**: To drop the dependency on `FrameworkBundle`, the following solutions can be followed:
>
> * implement `ContainerAwareInterface` and use `ContainerAwareTrait`
> * or register as a service and inject explicitely the dependencies
Finally, `FrameworkBundle` provides its own Console `Application` that wraps the
Kernel to access its registered bundles. This is planned to be supported.
Kernel to access its registered bundles.

> **Note**: Some bundles, like `DoctrineBundle`, have a direct dependency on
> `FrameworkBundle`'s console `Application` making them incompatible with `MicroFrameworkBundle`.
### Missing Dependencies

To follow the "add what you need" micro framework philosohpy, there are many components
present in `FrameworkBundle` that are absent from `MicroFrameworkBundle`:

* `symfony/asset`
* `symfony/finder`
* `symfony/security-core`
* `symfony/security-csrf`
* `symfony/stopwatch`
Expand Down

0 comments on commit dad550d

Please sign in to comment.