File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
5
5
---
6
6
7
7
* Add argument ` $prepend ` to ` ContainerConfigurator::extension() ` to prepend the configuration instead of appending it
8
+ * Have ` ServiceLocator ` implement ` ServiceCollectionInterface `
8
9
9
10
7.0
10
11
---
Original file line number Diff line number Diff line change 16
16
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
17
17
use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
18
18
use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
19
+ use Symfony \Contracts \Service \ServiceCollectionInterface ;
19
20
use Symfony \Contracts \Service \ServiceLocatorTrait ;
20
- use Symfony \Contracts \Service \ServiceProviderInterface ;
21
21
use Symfony \Contracts \Service \ServiceSubscriberInterface ;
22
22
23
23
/**
26
26
*
27
27
* @template-covariant T of mixed
28
28
*
29
- * @implements ServiceProviderInterface <T>
29
+ * @implements ServiceCollectionInterface <T>
30
30
*/
31
- class ServiceLocator implements ServiceProviderInterface, \Countable
31
+ class ServiceLocator implements ServiceCollectionInterface
32
32
{
33
33
use ServiceLocatorTrait {
34
34
get as private doGet;
@@ -82,6 +82,13 @@ public function count(): int
82
82
return \count ($ this ->getProvidedServices ());
83
83
}
84
84
85
+ public function getIterator (): \Traversable
86
+ {
87
+ foreach ($ this ->getProvidedServices () as $ id => $ config ) {
88
+ yield $ id => $ this ->get ($ id );
89
+ }
90
+ }
91
+
85
92
private function createNotFoundException (string $ id ): NotFoundExceptionInterface
86
93
{
87
94
if ($ this ->loading ) {
Original file line number Diff line number Diff line change @@ -101,6 +101,17 @@ public function testProvidesServicesInformation()
101
101
'baz ' => '?string ' ,
102
102
]);
103
103
}
104
+
105
+ public function testIsCountableAndIterable ()
106
+ {
107
+ $ locator = $ this ->getServiceLocator ([
108
+ 'foo ' => fn () => 'bar ' ,
109
+ 'bar ' => fn () => 'baz ' ,
110
+ ]);
111
+
112
+ $ this ->assertCount (2 , $ locator );
113
+ $ this ->assertSame (['foo ' => 'bar ' , 'bar ' => 'baz ' ], iterator_to_array ($ locator ));
114
+ }
104
115
}
105
116
106
117
class SomeServiceSubscriber implements ServiceSubscriberInterface
Original file line number Diff line number Diff line change 19
19
"php" : " >=8.2" ,
20
20
"psr/container" : " ^1.1|^2.0" ,
21
21
"symfony/deprecation-contracts" : " ^2.5|^3" ,
22
- "symfony/service-contracts" : " ^3.3 " ,
22
+ "symfony/service-contracts" : " ^3.5 " ,
23
23
"symfony/var-exporter" : " ^6.4|^7.0"
24
24
},
25
25
"require-dev" : {
You can’t perform that action at this time.
0 commit comments