32
32
use Symfony \Component \DependencyInjection \Tests \Fixtures \AutoconfiguredInterface2 ;
33
33
use Symfony \Component \DependencyInjection \Tests \Fixtures \AutoconfiguredService1 ;
34
34
use Symfony \Component \DependencyInjection \Tests \Fixtures \AutoconfiguredService2 ;
35
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \AutowireLocatorConsumer ;
35
36
use Symfony \Component \DependencyInjection \Tests \Fixtures \BarTagClass ;
36
37
use Symfony \Component \DependencyInjection \Tests \Fixtures \FooBarTaggedClass ;
37
38
use Symfony \Component \DependencyInjection \Tests \Fixtures \FooBarTaggedForDefaultPriorityClass ;
38
39
use Symfony \Component \DependencyInjection \Tests \Fixtures \FooTagClass ;
39
- use Symfony \Component \DependencyInjection \Tests \Fixtures \IteratorConsumer ;
40
- use Symfony \Component \DependencyInjection \Tests \Fixtures \IteratorConsumerWithDefaultIndexMethod ;
41
- use Symfony \Component \DependencyInjection \Tests \Fixtures \IteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ;
42
- use Symfony \Component \DependencyInjection \Tests \Fixtures \IteratorConsumerWithDefaultPriorityMethod ;
43
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumer ;
44
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerConsumer ;
45
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerFactory ;
46
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerWithDefaultIndexMethod ;
47
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ;
48
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerWithDefaultPriorityMethod ;
49
- use Symfony \Component \DependencyInjection \Tests \Fixtures \LocatorConsumerWithoutIndex ;
50
40
use Symfony \Component \DependencyInjection \Tests \Fixtures \StaticMethodTag ;
51
41
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedConsumerWithExclude ;
42
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedIteratorConsumer ;
43
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedIteratorConsumerWithDefaultIndexMethod ;
44
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ;
45
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedIteratorConsumerWithDefaultPriorityMethod ;
46
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumer ;
47
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerConsumer ;
48
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerFactory ;
49
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerWithDefaultIndexMethod ;
50
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ;
51
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerWithDefaultPriorityMethod ;
52
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedLocatorConsumerWithoutIndex ;
52
53
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedService1 ;
53
54
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedService2 ;
54
55
use Symfony \Component \DependencyInjection \Tests \Fixtures \TaggedService3 ;
@@ -388,6 +389,30 @@ public function testTaggedServiceWithIndexAttributeAndDefaultMethod()
388
389
$ this ->assertSame (['bar_tab_class_with_defaultmethod ' => $ container ->get (BarTagClass::class), 'foo ' => $ container ->get (FooTagClass::class)], $ param );
389
390
}
390
391
392
+ public function testLocatorConfiguredViaAttribute ()
393
+ {
394
+ $ container = new ContainerBuilder ();
395
+ $ container ->register (BarTagClass::class)
396
+ ->setPublic (true )
397
+ ;
398
+ $ container ->register (FooTagClass::class)
399
+ ->setPublic (true )
400
+ ;
401
+ $ container ->register (AutowireLocatorConsumer::class)
402
+ ->setAutowired (true )
403
+ ->setPublic (true )
404
+ ;
405
+
406
+ $ container ->compile ();
407
+
408
+ /** @var AutowireLocatorConsumer $s */
409
+ $ s = $ container ->get (AutowireLocatorConsumer::class);
410
+
411
+ self ::assertSame ($ container ->get (BarTagClass::class), $ s ->locator ->get (BarTagClass::class));
412
+ self ::assertSame ($ container ->get (FooTagClass::class), $ s ->locator ->get ('with_key ' ));
413
+ self ::assertFalse ($ s ->locator ->has ('nullable ' ));
414
+ }
415
+
391
416
public function testTaggedServiceWithIndexAttributeAndDefaultMethodConfiguredViaAttribute ()
392
417
{
393
418
$ container = new ContainerBuilder ();
@@ -399,14 +424,14 @@ public function testTaggedServiceWithIndexAttributeAndDefaultMethodConfiguredVia
399
424
->setPublic (true )
400
425
->addTag ('foo_bar ' , ['foo ' => 'foo ' ])
401
426
;
402
- $ container ->register (IteratorConsumer ::class)
427
+ $ container ->register (TaggedIteratorConsumer ::class)
403
428
->setAutowired (true )
404
429
->setPublic (true )
405
430
;
406
431
407
432
$ container ->compile ();
408
433
409
- $ s = $ container ->get (IteratorConsumer ::class);
434
+ $ s = $ container ->get (TaggedIteratorConsumer ::class);
410
435
411
436
$ param = iterator_to_array ($ s ->getParam ()->getIterator ());
412
437
$ this ->assertSame (['bar_tab_class_with_defaultmethod ' => $ container ->get (BarTagClass::class), 'foo ' => $ container ->get (FooTagClass::class)], $ param );
@@ -423,14 +448,14 @@ public function testTaggedIteratorWithDefaultIndexMethodConfiguredViaAttribute()
423
448
->setPublic (true )
424
449
->addTag ('foo_bar ' )
425
450
;
426
- $ container ->register (IteratorConsumerWithDefaultIndexMethod ::class)
451
+ $ container ->register (TaggedIteratorConsumerWithDefaultIndexMethod ::class)
427
452
->setAutowired (true )
428
453
->setPublic (true )
429
454
;
430
455
431
456
$ container ->compile ();
432
457
433
- $ s = $ container ->get (IteratorConsumerWithDefaultIndexMethod ::class);
458
+ $ s = $ container ->get (TaggedIteratorConsumerWithDefaultIndexMethod ::class);
434
459
435
460
$ param = iterator_to_array ($ s ->getParam ()->getIterator ());
436
461
$ this ->assertSame (['bar_tag_class ' => $ container ->get (BarTagClass::class), 'foo_tag_class ' => $ container ->get (FooTagClass::class)], $ param );
@@ -447,14 +472,14 @@ public function testTaggedIteratorWithDefaultPriorityMethodConfiguredViaAttribut
447
472
->setPublic (true )
448
473
->addTag ('foo_bar ' )
449
474
;
450
- $ container ->register (IteratorConsumerWithDefaultPriorityMethod ::class)
475
+ $ container ->register (TaggedIteratorConsumerWithDefaultPriorityMethod ::class)
451
476
->setAutowired (true )
452
477
->setPublic (true )
453
478
;
454
479
455
480
$ container ->compile ();
456
481
457
- $ s = $ container ->get (IteratorConsumerWithDefaultPriorityMethod ::class);
482
+ $ s = $ container ->get (TaggedIteratorConsumerWithDefaultPriorityMethod ::class);
458
483
459
484
$ param = iterator_to_array ($ s ->getParam ()->getIterator ());
460
485
$ this ->assertSame ([0 => $ container ->get (FooTagClass::class), 1 => $ container ->get (BarTagClass::class)], $ param );
@@ -471,14 +496,14 @@ public function testTaggedIteratorWithDefaultIndexMethodAndWithDefaultPriorityMe
471
496
->setPublic (true )
472
497
->addTag ('foo_bar ' )
473
498
;
474
- $ container ->register (IteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class)
499
+ $ container ->register (TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class)
475
500
->setAutowired (true )
476
501
->setPublic (true )
477
502
;
478
503
479
504
$ container ->compile ();
480
505
481
- $ s = $ container ->get (IteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class);
506
+ $ s = $ container ->get (TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class);
482
507
483
508
$ param = iterator_to_array ($ s ->getParam ()->getIterator ());
484
509
$ this ->assertSame (['foo_tag_class ' => $ container ->get (FooTagClass::class), 'bar_tag_class ' => $ container ->get (BarTagClass::class)], $ param );
@@ -495,15 +520,15 @@ public function testTaggedLocatorConfiguredViaAttribute()
495
520
->setPublic (true )
496
521
->addTag ('foo_bar ' , ['foo ' => 'foo ' ])
497
522
;
498
- $ container ->register (LocatorConsumer ::class)
523
+ $ container ->register (TaggedLocatorConsumer ::class)
499
524
->setAutowired (true )
500
525
->setPublic (true )
501
526
;
502
527
503
528
$ container ->compile ();
504
529
505
- /** @var LocatorConsumer $s */
506
- $ s = $ container ->get (LocatorConsumer ::class);
530
+ /** @var TaggedLocatorConsumer $s */
531
+ $ s = $ container ->get (TaggedLocatorConsumer ::class);
507
532
508
533
$ locator = $ s ->getLocator ();
509
534
self ::assertSame ($ container ->get (BarTagClass::class), $ locator ->get ('bar_tab_class_with_defaultmethod ' ));
@@ -521,15 +546,15 @@ public function testTaggedLocatorConfiguredViaAttributeWithoutIndex()
521
546
->setPublic (true )
522
547
->addTag ('foo_bar ' )
523
548
;
524
- $ container ->register (LocatorConsumerWithoutIndex ::class)
549
+ $ container ->register (TaggedLocatorConsumerWithoutIndex ::class)
525
550
->setAutowired (true )
526
551
->setPublic (true )
527
552
;
528
553
529
554
$ container ->compile ();
530
555
531
- /** @var LocatorConsumerWithoutIndex $s */
532
- $ s = $ container ->get (LocatorConsumerWithoutIndex ::class);
556
+ /** @var TaggedLocatorConsumerWithoutIndex $s */
557
+ $ s = $ container ->get (TaggedLocatorConsumerWithoutIndex ::class);
533
558
534
559
$ locator = $ s ->getLocator ();
535
560
self ::assertSame ($ container ->get (BarTagClass::class), $ locator ->get (BarTagClass::class));
@@ -547,15 +572,15 @@ public function testTaggedLocatorWithDefaultIndexMethodConfiguredViaAttribute()
547
572
->setPublic (true )
548
573
->addTag ('foo_bar ' )
549
574
;
550
- $ container ->register (LocatorConsumerWithDefaultIndexMethod ::class)
575
+ $ container ->register (TaggedLocatorConsumerWithDefaultIndexMethod ::class)
551
576
->setAutowired (true )
552
577
->setPublic (true )
553
578
;
554
579
555
580
$ container ->compile ();
556
581
557
- /** @var LocatorConsumerWithoutIndex $s */
558
- $ s = $ container ->get (LocatorConsumerWithDefaultIndexMethod ::class);
582
+ /** @var TaggedLocatorConsumerWithoutIndex $s */
583
+ $ s = $ container ->get (TaggedLocatorConsumerWithDefaultIndexMethod ::class);
559
584
560
585
$ locator = $ s ->getLocator ();
561
586
self ::assertSame ($ container ->get (BarTagClass::class), $ locator ->get ('bar_tag_class ' ));
@@ -573,15 +598,15 @@ public function testTaggedLocatorWithDefaultPriorityMethodConfiguredViaAttribute
573
598
->setPublic (true )
574
599
->addTag ('foo_bar ' )
575
600
;
576
- $ container ->register (LocatorConsumerWithDefaultPriorityMethod ::class)
601
+ $ container ->register (TaggedLocatorConsumerWithDefaultPriorityMethod ::class)
577
602
->setAutowired (true )
578
603
->setPublic (true )
579
604
;
580
605
581
606
$ container ->compile ();
582
607
583
- /** @var LocatorConsumerWithoutIndex $s */
584
- $ s = $ container ->get (LocatorConsumerWithDefaultPriorityMethod ::class);
608
+ /** @var TaggedLocatorConsumerWithoutIndex $s */
609
+ $ s = $ container ->get (TaggedLocatorConsumerWithDefaultPriorityMethod ::class);
585
610
586
611
$ locator = $ s ->getLocator ();
587
612
@@ -602,15 +627,15 @@ public function testTaggedLocatorWithDefaultIndexMethodAndWithDefaultPriorityMet
602
627
->setPublic (true )
603
628
->addTag ('foo_bar ' )
604
629
;
605
- $ container ->register (LocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class)
630
+ $ container ->register (TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class)
606
631
->setAutowired (true )
607
632
->setPublic (true )
608
633
;
609
634
610
635
$ container ->compile ();
611
636
612
- /** @var LocatorConsumerWithoutIndex $s */
613
- $ s = $ container ->get (LocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class);
637
+ /** @var TaggedLocatorConsumerWithoutIndex $s */
638
+ $ s = $ container ->get (TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod ::class);
614
639
615
640
$ locator = $ s ->getLocator ();
616
641
@@ -629,18 +654,18 @@ public function testNestedDefinitionWithAutoconfiguredConstructorArgument()
629
654
->setPublic (true )
630
655
->addTag ('foo_bar ' , ['foo ' => 'foo ' ])
631
656
;
632
- $ container ->register (LocatorConsumerConsumer ::class)
657
+ $ container ->register (TaggedLocatorConsumerConsumer ::class)
633
658
->setPublic (true )
634
659
->setArguments ([
635
- (new Definition (LocatorConsumer ::class))
660
+ (new Definition (TaggedLocatorConsumer ::class))
636
661
->setAutowired (true ),
637
662
])
638
663
;
639
664
640
665
$ container ->compile ();
641
666
642
- /** @var LocatorConsumerConsumer $s */
643
- $ s = $ container ->get (LocatorConsumerConsumer ::class);
667
+ /** @var TaggedLocatorConsumerConsumer $s */
668
+ $ s = $ container ->get (TaggedLocatorConsumerConsumer ::class);
644
669
645
670
$ locator = $ s ->getLocatorConsumer ()->getLocator ();
646
671
self ::assertSame ($ container ->get (FooTagClass::class), $ locator ->get ('foo ' ));
@@ -653,17 +678,17 @@ public function testFactoryWithAutoconfiguredArgument()
653
678
->setPublic (true )
654
679
->addTag ('foo_bar ' , ['key ' => 'my_service ' ])
655
680
;
656
- $ container ->register (LocatorConsumerFactory ::class);
657
- $ container ->register (LocatorConsumer ::class)
681
+ $ container ->register (TaggedLocatorConsumerFactory ::class);
682
+ $ container ->register (TaggedLocatorConsumer ::class)
658
683
->setPublic (true )
659
684
->setAutowired (true )
660
- ->setFactory (new Reference (LocatorConsumerFactory ::class))
685
+ ->setFactory (new Reference (TaggedLocatorConsumerFactory ::class))
661
686
;
662
687
663
688
$ container ->compile ();
664
689
665
- /** @var LocatorConsumer $s */
666
- $ s = $ container ->get (LocatorConsumer ::class);
690
+ /** @var TaggedLocatorConsumer $s */
691
+ $ s = $ container ->get (TaggedLocatorConsumer ::class);
667
692
668
693
$ locator = $ s ->getLocator ();
669
694
self ::assertSame ($ container ->get (FooTagClass::class), $ locator ->get ('my_service ' ));
0 commit comments