Skip to content

Commit 8d63aec

Browse files
author
Yann Eugoné
committed
Merge pull request #8 from yann-eugone/hotfix/compiler-pass-register
Fixed wrong usage of container while registering compiler passes
2 parents 5bd0edc + ff71241 commit 8d63aec

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

DependencyInjection/CompilerPass/ConventionedEnumCollectorCompilerPass.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010
*/
1111
class ConventionedEnumCollectorCompilerPass implements CompilerPassInterface
1212
{
13-
/**
14-
* @var array
15-
*/
16-
private $bundles;
17-
18-
/**
19-
* @param array $bundles
20-
*/
21-
public function __construct(array $bundles)
22-
{
23-
$this->bundles = $bundles;
24-
}
25-
2613
/**
2714
* {@inheritdoc}
2815
*/
2916
public function process(ContainerBuilder $container)
3017
{
31-
foreach ($this->bundles as $bundleClass) {
18+
$bundles = $container->getParameter('enum.register_bundles');
19+
20+
if (!$bundles) {
21+
return;
22+
}
23+
24+
if (true === $bundles) {
25+
$bundles = $container->getParameter('kernel.bundles');
26+
} else {
27+
$bundles = (array) $bundles;
28+
}
29+
30+
foreach ($bundles as $bundleClass) {
3231
$declarativePass = new DeclarativeEnumCollectorCompilerPass($bundleClass);
3332
$declarativePass->process($container);
3433
}

EnumBundle.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ class EnumBundle extends Bundle
1818
*/
1919
public function build(ContainerBuilder $container)
2020
{
21-
if ($bundles = $container->getParameter('enum.register_bundles')) {
22-
if (true === $bundles) {
23-
$bundles = $container->getParameter('kernel.bundles');
24-
} else {
25-
$bundles = (array) $bundles;
26-
}
27-
$container->addCompilerPass(new ConventionedEnumCollectorCompilerPass($bundles));
28-
}
29-
$container->addCompilerPass(new TaggedEnumCollectorCompilerPass);
21+
$container
22+
->addCompilerPass(new ConventionedEnumCollectorCompilerPass())
23+
->addCompilerPass(new TaggedEnumCollectorCompilerPass)
24+
;
3025
}
3126

3227
/**

Tests/DependencyInjection/CompilerPass/ConventionedEnumCollectorCompilerPassTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function testCollectThroughBundles($bundle, $prefix)
2828

2929
$namespace = (new \ReflectionClass($bundle))->getNamespaceName();
3030

31+
$container->getParameter('enum.register_bundles')
32+
->shouldBeCalled()
33+
->willReturn([$bundle]);
34+
3135
$container
3236
->setDefinition(
3337
$prefix.'.enum.dummy',
@@ -66,7 +70,7 @@ public function testCollectThroughBundles($bundle, $prefix)
6670
)
6771
->shouldBeCalled();
6872

69-
$compiler = new ConventionedEnumCollectorCompilerPass([$bundle]);
73+
$compiler = new ConventionedEnumCollectorCompilerPass();
7074
$compiler->process($container->reveal());
7175
}
7276

0 commit comments

Comments
 (0)