|
15 | 15 | use Psr\Container\ContainerInterface;
|
16 | 16 | use Symfony\Component\Config\FileLocator;
|
17 | 17 | use Symfony\Component\DependencyInjection\Alias;
|
| 18 | +use Symfony\Component\DependencyInjection\Argument\BoundArgument; |
18 | 19 | use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
19 | 20 | use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
20 | 21 | use Symfony\Component\DependencyInjection\ChildDefinition;
|
|
47 | 48 | use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod;
|
48 | 49 | use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithDefaultPriorityMethod;
|
49 | 50 | use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithoutIndex;
|
| 51 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithServiceSubscriber; |
50 | 52 | use Symfony\Component\DependencyInjection\Tests\Fixtures\StaticMethodTag;
|
51 | 53 | use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedConsumerWithExclude;
|
52 | 54 | use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService1;
|
@@ -1085,6 +1087,66 @@ public function testTaggedIteratorAndLocatorWithExclude()
|
1085 | 1087 | $this->assertTrue($locator->has(AutoconfiguredService2::class));
|
1086 | 1088 | $this->assertFalse($locator->has(TaggedConsumerWithExclude::class));
|
1087 | 1089 | }
|
| 1090 | + |
| 1091 | + public function testAutowireAttributeHasPriorityOverBindings() |
| 1092 | + { |
| 1093 | + $container = new ContainerBuilder(); |
| 1094 | + $container->register(FooTagClass::class) |
| 1095 | + ->setPublic(true) |
| 1096 | + ->addTag('foo_bar', ['key' => 'tagged_service']) |
| 1097 | + ; |
| 1098 | + $container->register(LocatorConsumerWithServiceSubscriber::class) |
| 1099 | + ->setBindings([ |
| 1100 | + '$locator' => new BoundArgument(new Reference('service_container'), false), |
| 1101 | + ]) |
| 1102 | + ->setPublic(true) |
| 1103 | + ->setAutowired(true) |
| 1104 | + ->addTag('container.service_subscriber') |
| 1105 | + ; |
| 1106 | + $container->register('subscribed_service', \stdClass::class) |
| 1107 | + ->setPublic(true) |
| 1108 | + ; |
| 1109 | + |
| 1110 | + $container->compile(); |
| 1111 | + |
| 1112 | + /** @var LocatorConsumerWithServiceSubscriber $s */ |
| 1113 | + $s = $container->get(LocatorConsumerWithServiceSubscriber::class); |
| 1114 | + |
| 1115 | + self::assertInstanceOf(ContainerInterface::class, $subscriberLocator = $s->getContainer()); |
| 1116 | + self::assertTrue($subscriberLocator->has('subscribed_service')); |
| 1117 | + self::assertNotSame($subscriberLocator, $taggedLocator = $s->getLocator()); |
| 1118 | + self::assertInstanceOf(ContainerInterface::class, $taggedLocator); |
| 1119 | + self::assertTrue($taggedLocator->has('tagged_service')); |
| 1120 | + } |
| 1121 | + |
| 1122 | + public function testBindingsWithAutowireAttributeAndAutowireFalse() |
| 1123 | + { |
| 1124 | + $container = new ContainerBuilder(); |
| 1125 | + $container->register(FooTagClass::class) |
| 1126 | + ->setPublic(true) |
| 1127 | + ->addTag('foo_bar', ['key' => 'tagged_service']) |
| 1128 | + ; |
| 1129 | + $container->register(LocatorConsumerWithServiceSubscriber::class) |
| 1130 | + ->setBindings([ |
| 1131 | + '$locator' => new BoundArgument(new Reference('service_container'), false), |
| 1132 | + ]) |
| 1133 | + ->setPublic(true) |
| 1134 | + ->setAutowired(false) |
| 1135 | + ->addTag('container.service_subscriber') |
| 1136 | + ; |
| 1137 | + $container->register('subscribed_service', \stdClass::class) |
| 1138 | + ->setPublic(true) |
| 1139 | + ; |
| 1140 | + |
| 1141 | + $container->compile(); |
| 1142 | + |
| 1143 | + /** @var LocatorConsumerWithServiceSubscriber $s */ |
| 1144 | + $s = $container->get(LocatorConsumerWithServiceSubscriber::class); |
| 1145 | + |
| 1146 | + self::assertNull($s->getContainer()); |
| 1147 | + self::assertInstanceOf(ContainerInterface::class, $taggedLocator = $s->getLocator()); |
| 1148 | + self::assertSame($container, $taggedLocator); |
| 1149 | + } |
1088 | 1150 | }
|
1089 | 1151 |
|
1090 | 1152 | class ServiceSubscriberStub implements ServiceSubscriberInterface
|
|
0 commit comments