Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 388e4b3

Browse filesBrowse files
[DI] Make tagged abstract services throw earlier
1 parent cd06c12 commit 388e4b3
Copy full SHA for 388e4b3

File tree

Expand file treeCollapse file tree

27 files changed

+94
-79
lines changed
Filter options
Expand file treeCollapse file tree

27 files changed

+94
-79
lines changed

‎src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function process(ContainerBuilder $container)
5555
return;
5656
}
5757

58-
$taggedSubscribers = $container->findTaggedServiceIds($this->tagPrefix.'.event_subscriber');
59-
$taggedListeners = $container->findTaggedServiceIds($this->tagPrefix.'.event_listener');
58+
$taggedSubscribers = $container->findTaggedServiceIds($this->tagPrefix.'.event_subscriber', true);
59+
$taggedListeners = $container->findTaggedServiceIds($this->tagPrefix.'.event_listener', true);
6060

6161
if (empty($taggedSubscribers) && empty($taggedListeners)) {
6262
return;
@@ -78,10 +78,6 @@ public function process(ContainerBuilder $container)
7878

7979
uasort($subscribers, $sortFunc);
8080
foreach ($subscribers as $id => $instance) {
81-
if ($container->getDefinition($id)->isAbstract()) {
82-
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
83-
}
84-
8581
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
8682
}
8783
}
@@ -94,10 +90,6 @@ public function process(ContainerBuilder $container)
9490

9591
uasort($listeners, $sortFunc);
9692
foreach ($listeners as $id => $instance) {
97-
if ($container->getDefinition($id)->isAbstract()) {
98-
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
99-
}
100-
10193
$em->addMethodCall('addEventListener', array(
10294
array_unique($instance['event']),
10395
isset($instance['lazy']) && $instance['lazy'] ? $id : new Reference($id),

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function process(ContainerBuilder $container)
3232
}
3333

3434
$clearers = array();
35-
foreach ($container->findTaggedServiceIds('kernel.cache_clearer') as $id => $attributes) {
35+
foreach ($container->findTaggedServiceIds('kernel.cache_clearer', true) as $id => $attributes) {
3636
$clearers[] = new Reference($id);
3737
}
3838

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public function process(ContainerBuilder $container)
3030
// routing
3131
if ($container->has('router')) {
3232
$definition = $container->findDefinition('router');
33-
foreach ($container->findTaggedServiceIds('routing.expression_language_provider') as $id => $attributes) {
33+
foreach ($container->findTaggedServiceIds('routing.expression_language_provider', true) as $id => $attributes) {
3434
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
3535
}
3636
}
3737

3838
// security
3939
if ($container->has('security.access.expression_voter')) {
4040
$definition = $container->findDefinition('security.access.expression_voter');
41-
foreach ($container->findTaggedServiceIds('security.expression_language_provider') as $id => $attributes) {
41+
foreach ($container->findTaggedServiceIds('security.expression_language_provider', true) as $id => $attributes) {
4242
$definition->addMethodCall('addExpressionLanguageProvider', array(new Reference($id)));
4343
}
4444
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function process(ContainerBuilder $container)
3333

3434
$collectors = new \SplPriorityQueue();
3535
$order = PHP_INT_MAX;
36-
foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
36+
foreach ($container->findTaggedServiceIds('data_collector', true) as $id => $attributes) {
3737
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
3838
$template = null;
3939

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function process(ContainerBuilder $container)
3232

3333
if ($container->hasDefinition('templating.engine.php')) {
3434
$helpers = array();
35-
foreach ($container->findTaggedServiceIds('templating.helper') as $id => $attributes) {
35+
foreach ($container->findTaggedServiceIds('templating.helper', true) as $id => $attributes) {
3636
if (isset($attributes[0]['alias'])) {
3737
$helpers[$attributes[0]['alias']] = $id;
3838
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslationDumperPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslationDumperPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function process(ContainerBuilder $container)
2828

2929
$definition = $container->getDefinition('translation.writer');
3030

31-
foreach ($container->findTaggedServiceIds('translation.dumper') as $id => $attributes) {
31+
foreach ($container->findTaggedServiceIds('translation.dumper', true) as $id => $attributes) {
3232
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
3333
}
3434
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslationExtractorPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslationExtractorPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function process(ContainerBuilder $container)
2929

3030
$definition = $container->getDefinition('translation.extractor');
3131

32-
foreach ($container->findTaggedServiceIds('translation.extractor') as $id => $attributes) {
32+
foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
3333
if (!isset($attributes[0]['alias'])) {
3434
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
3535
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslatorPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslatorPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function process(ContainerBuilder $container)
2626

2727
$loaders = array();
2828
$loaderRefs = array();
29-
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
29+
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
3030
$loaderRefs[$id] = new Reference($id);
3131
$loaders[$id][] = $attributes[0]['alias'];
3232
if (isset($attributes[0]['legacy-alias'])) {

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ValidateWorkflowsPass implements CompilerPassInterface
2525
{
2626
public function process(ContainerBuilder $container)
2727
{
28-
$taggedServices = $container->findTaggedServiceIds('workflow.definition');
28+
$taggedServices = $container->findTaggedServiceIds('workflow.definition', true);
2929
foreach ($taggedServices as $id => $tags) {
3030
$definition = $container->get($id);
3131
foreach ($tags as $tag) {

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php
+18-3Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public function testThatConstraintValidatorServicesAreProcessed()
3434
->addTag('validator.constraint_validator', array('alias' => 'my_constraint_validator_alias1'));
3535
$container->register('my_constraint_validator_service2', Validator2::class)
3636
->addTag('validator.constraint_validator');
37-
$container->register('my_abstract_constraint_validator')
38-
->setAbstract(true)
39-
->addTag('validator.constraint_validator');
4037

4138
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
4239
$addConstraintValidatorsPass->process($container);
@@ -49,6 +46,24 @@ public function testThatConstraintValidatorServicesAreProcessed()
4946
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
5047
}
5148

49+
/**
50+
* @expectedException \InvalidArgumentException
51+
* @expectedExceptionMessage The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.
52+
*/
53+
public function testAbstractConstraintValidator()
54+
{
55+
$container = new ContainerBuilder();
56+
$validatorFactory = $container->register('validator.validator_factory')
57+
->addArgument(array());
58+
59+
$container->register('my_abstract_constraint_validator')
60+
->setAbstract(true)
61+
->addTag('validator.constraint_validator');
62+
63+
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
64+
$addConstraintValidatorsPass->process($container);
65+
}
66+
5267
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
5368
{
5469
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.