Skip to content

Commit 670a23e

Browse files
committed
Add extra validation for dynamically referenced services
In Symfony 4, services are private by default. But our registries are still requiring to use public services for now, so this must be validated to provide better error messages.
1 parent 1a8ef6d commit 670a23e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/DependencyInjection/Compiler/RegisterPagerPersistersPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function process(ContainerBuilder $container)
2929
$registry = $container->getDefinition('fos_elastica.pager_persister_registry');
3030

3131
$nameToServiceIdMap = [];
32-
foreach ($container->findTaggedServiceIds('fos_elastica.pager_persister') as $id => $attributes) {
32+
foreach ($container->findTaggedServiceIds('fos_elastica.pager_persister', true) as $id => $attributes) {
3333
foreach ($attributes as $attribute) {
3434
if (!isset($attribute['persisterName'])) {
3535
throw new \InvalidArgumentException(sprintf('Elastica pager persister "%s" must specify the "persisterName" attribute.', $id));
@@ -53,6 +53,10 @@ public function process(ContainerBuilder $container)
5353
$this->assertClassImplementsPagerPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
5454
}
5555

56+
if (!$persisterDef->isPublic()) {
57+
throw new \InvalidArgumentException(sprintf('Elastica pager persister "%s" must be a public service', $id));
58+
}
59+
5660
$nameToServiceIdMap[$persisterName] = $id;
5761
}
5862
}

src/DependencyInjection/Compiler/RegisterPagerProvidersPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function process(ContainerBuilder $container)
3030
$registry = $container->getDefinition('fos_elastica.pager_provider_registry');
3131

3232
$registeredProviders = [];
33-
foreach ($container->findTaggedServiceIds('fos_elastica.pager_provider') as $id => $attributes) {
33+
foreach ($container->findTaggedServiceIds('fos_elastica.pager_provider', true) as $id => $attributes) {
3434
foreach ($attributes as $attribute) {
3535
if (!isset($attribute['type'])) {
3636
throw new \InvalidArgumentException(sprintf('Elastica provider "%s" must specify the "type" attribute.', $id));
@@ -56,6 +56,10 @@ public function process(ContainerBuilder $container)
5656
$this->assertClassImplementsPagerProviderInterface($id, $container->getParameterBag()->resolveValue($providerDef->getClass()));
5757
}
5858

59+
if (!$providerDef->isPublic()) {
60+
throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must be a public service', $id));
61+
}
62+
5963
$registeredProviders[$index][$type] = $id;
6064
}
6165
}

src/DependencyInjection/Compiler/RegisterPersistersPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function process(ContainerBuilder $container)
3030
$registry = $container->getDefinition('fos_elastica.persister_registry');
3131

3232
$registeredPersisters = [];
33-
foreach ($container->findTaggedServiceIds('fos_elastica.persister') as $id => $attributes) {
33+
foreach ($container->findTaggedServiceIds('fos_elastica.persister', true) as $id => $attributes) {
3434
foreach ($attributes as $attribute) {
3535
if (!isset($attribute['type'])) {
3636
throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must specify the "type" attribute.', $id));
@@ -56,6 +56,10 @@ public function process(ContainerBuilder $container)
5656
$this->assertClassImplementsPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
5757
}
5858

59+
if (!$persisterDef->isPublic()) {
60+
throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must be a public service', $id));
61+
}
62+
5963
$registeredPersisters[$index][$type] = $id;
6064
}
6165
}

0 commit comments

Comments
 (0)