File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
src/Symfony/Component/DependencyInjection Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
Original file line number Diff line number Diff line change 32
32
use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumer ;
33
33
use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerConsumer ;
34
34
use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerFactory ;
35
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerWithoutIndex ;
35
36
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedService1 ;
36
37
use Symfony \Component \DependencyInjection \Tests \F
8000
ixtures \TaggedService2 ;
37
38
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedService3 ;
@@ -403,6 +404,35 @@ public function testTaggedLocatorConfiguredViaAttribute()
403
404
self ::assertSame ($ container ->get (FooTagClass::class), $ locator ->get ('foo ' ));
404
405
}
405
406
407
+ /**
408
+ * @requires PHP 8
409
+ */
410
+ public function testTaggedLocatorConfiguredViaAttributeWithoutIndex ()
411
+ {
412
+ $ container = new ContainerBuilder ();
413
+ $ container ->register (BarTagClass::class)
414
+ ->setPublic (true )
415
+ ->addTag ('foo_bar ' )
416
+ ;
417
+ $ container ->register (FooTagClass::class)
418
+ ->setPublic (true )
419
+ ->addTag ('foo_bar ' )
420
+ ;
421
+ $ container ->register (LocatorConsumerWithoutIndex::class)
422
+ ->setAutowired (true )
423
+ ->setPublic (true )
424
+ ;
425
+
426
+ $ container ->compile ();
427
+
428
+ /** @var LocatorConsumerWithoutIndex $s */
429
+ $ s = $ container ->get (LocatorConsumerWithoutIndex::class);
430
+
431
+ $ locator = $ s ->getLocator ();
432
+ self ::assertSame ($ container ->get (BarTagClass::class), $ locator ->get (BarTagClass::class));
433
+ self ::assertSame ($ container ->get (FooTagClass::class), $ locator ->get (FooTagClass::class));
434
+ }
435
+
406
436
/**
407
437
* @requires PHP 8
408
438
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \DependencyInjection \Tests \Fixtures ;
13
+
14
+ use Psr \Container \ContainerInterface ;
15
+ use Symfony \Component \DependencyInjection \Attribute \TaggedLocator ;
16
+
17
+ final class LocatorConsumerWithoutIndex
18
+ {
19
+ public function __construct (
20
+ #[TaggedLocator('foo_bar ' )]
21
+ private ContainerInterface $ locator ,
22
+ ) {
23
+ }
24
+
25
+ public function getLocator (): ContainerInterface
26
+ {
27
+ return $ this ->locator ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments