Skip to content

Commit 1a8ef6d

Browse files
committed
Fix support for decorating persister services
Waiting until the before_removing step to check for persisters breaks support for service decoration, as it has already been resolved at this point (and so the original id won't be used anymore to reference the service). The first benefit was that the class was already resolved in case a parameter was used, but this is solved in a better way by resolving the value. The second benefit was that the class was already resolved when using definition inheritance. The interface validation is now skipped in such case (which should not fail anyway, as the parent service will likely be our own one in such case, which has a valid class).
1 parent dc5e6bf commit 1a8ef6d

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/DependencyInjection/Compiler/RegisterPagerPersistersPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public function process(ContainerBuilder $container)
4747
}
4848

4949
$persisterDef = $container->getDefinition($id);
50-
if (!$persisterDef->getFactory()) {
50+
if (!$persisterDef->getFactory() && $persisterDef->getClass()) {
5151
// You are on your own if you use a factory to create a persister.
5252
// It would fail in runtime if the factory does not return a proper persister.
53-
$this->assertClassImplementsPagerPersisterInterface($id, $persisterDef->getClass());
53+
$this->assertClassImplementsPagerPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
5454
}
5555

5656
$nameToServiceIdMap[$persisterName] = $id;
@@ -79,4 +79,4 @@ private function assertClassImplementsPagerPersisterInterface($persisterId, $per
7979
));
8080
}
8181
}
82-
}
82+
}

src/DependencyInjection/Compiler/RegisterPagerProvidersPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function process(ContainerBuilder $container)
5050
}
5151

5252
$providerDef = $container->getDefinition($id);
53-
if (!$providerDef->getFactory()) {
53+
if (!$providerDef->getFactory() && $providerDef->getClass()) {
5454
// You are on your own if you use a factory to create a provider.
5555
// It would fail in runtime if the factory does not return a proper provider.
56-
$this->assertClassImplementsPagerProviderInterface($id, $providerDef->getClass());
56+
$this->assertClassImplementsPagerProviderInterface($id, $container->getParameterBag()->resolveValue($providerDef->getClass()));
5757
}
5858

5959
$registeredProviders[$index][$type] = $id;

src/DependencyInjection/Compiler/RegisterPersistersPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function process(ContainerBuilder $container)
5050
}
5151

5252
$persisterDef = $container->getDefinition($id);
53-
if (!$persisterDef->getFactory()) {
53+
if (!$persisterDef->getFactory() && $persisterDef->getClass()) {
5454
// You are on your own if you use a factory to create a persister.
5555
// It would fail in runtime if the factory does not return a proper persister.
56-
$this->assertClassImplementsPersisterInterface($id, $persisterDef->getClass());
56+
$this->assertClassImplementsPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
5757
}
5858

5959
$registeredPersisters[$index][$type] = $id;
@@ -82,4 +82,4 @@ private function assertClassImplementsPersisterInterface($persisterId, $persiste
8282
));
8383
}
8484
}
85-
}
85+
}

src/FOSElasticaBundle.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use FOS\ElasticaBundle\DependencyInjection\Compiler\RegisterPagerProvidersPass;
2020
use FOS\ElasticaBundle\DependencyInjection\Compiler\RegisterPersistersPass;
21-
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
2221
use Symfony\Component\HttpKernel\Bundle\Bundle;
2322

2423
class FOSElasticaBundle extends Bundle
@@ -32,8 +31,8 @@ public function build(ContainerBuilder $container)
3231

3332
$container->addCompilerPass(new ConfigSourcePass());
3433
$container->addCompilerPass(new IndexPass());
35-
$container->addCompilerPass(new RegisterPagerProvidersPass(), PassConfig::TYPE_BEFORE_REMOVING);
36-
$container->addCompilerPass(new RegisterPersistersPass(), PassConfig::TYPE_BEFORE_REMOVING);
34+
$container->addCompilerPass(new RegisterPagerProvidersPass());
35+
$container->addCompilerPass(new RegisterPersistersPass());
3736
$container->addCompilerPass(new RegisterPagerPersistersPass());
3837
$container->addCompilerPass(new TransformerPass());
3938
}

0 commit comments

Comments
 (0)