Skip to content

Commit 4a9e874

Browse files
committed
[DependencyInjection] Add ServiceCollectionInterface
1 parent b990b26 commit 4a9e874

File tree

14 files changed

+63
-13
lines changed

14 files changed

+63
-13
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"psr/http-message": "^1.0|^2.0",
4848
"psr/link": "^1.1|^2.0",
4949
"psr/log": "^1|^2|^3",
50-
"symfony/contracts": "^2.5|^3.0",
50+
"symfony/contracts": "^3.5",
5151
"symfony/polyfill-ctype": "~1.8",
5252
"symfony/polyfill-intl-grapheme": "~1.0",
5353
"symfony/polyfill-intl-icu": "~1.0",
@@ -206,7 +206,7 @@
206206
"url": "src/Symfony/Contracts",
207207
"options": {
208208
"versions": {
209-
"symfony/contracts": "3.4.x-dev"
209+
"symfony/contracts": "3.5.x-dev"
210210
}
211211
}
212212
},

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add argument `$prepend` to `ContainerConfigurator::extension()` to prepend the configuration instead of appending it
8+
* Have `ServiceLocator` implement `ServiceCollectionInterface`
89

910
7.0
1011
---

src/Symfony/Component/DependencyInjection/ServiceLocator.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1717
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1818
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
19+
use Symfony\Contracts\Service\ServiceCollectionInterface;
1920
use Symfony\Contracts\Service\ServiceLocatorTrait;
20-
use Symfony\Contracts\Service\ServiceProviderInterface;
2121
use Symfony\Contracts\Service\ServiceSubscriberInterface;
2222

2323
/**
@@ -26,9 +26,9 @@
2626
*
2727
* @template-covariant T of mixed
2828
*
29-
* @implements ServiceProviderInterface<T>
29+
* @implements ServiceCollectionInterface<T>
3030
*/
31-
class ServiceLocator implements ServiceProviderInterface, \Countable
31+
class ServiceLocator implements ServiceCollectionInterface
3232
{
3333
use ServiceLocatorTrait {
3434
get as private doGet;
@@ -82,6 +82,13 @@ public function count(): int
8282
return \count($this->getProvidedServices());
8383
}
8484

85+
public function getIterator(): \Traversable
86+
{
87+
foreach ($this->getProvidedServices() as $id => $config) {
88+
yield $id => $this->get($id);
89+
}
90+
}
91+
8592
private function createNotFoundException(string $id): NotFoundExceptionInterface
8693
{
8794
if ($this->loading) {

src/Symfony/Component/DependencyInjection/Tests/ServiceLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ public function testProvidesServicesInformation()
101101
'baz' => '?string',
102102
]);
103103
}
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+
}
104115
}
105116

106117
class SomeServiceSubscriber implements ServiceSubscriberInterface

src/Symfony/Component/DependencyInjection/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=8.2",
2020
"psr/container": "^1.1|^2.0",
2121
"symfony/deprecation-contracts": "^2.5|^3",
22-
"symfony/service-contracts": "^3.3",
22+
"symfony/service-contracts": "^3.5",
2323
"symfony/var-exporter": "^6.4|^7.0"
2424
},
2525
"require-dev": {

src/Symfony/Contracts/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.5
5+
---
6+
7+
* Add `ServiceCollectionInterface`
8+
49
3.4
510
---
611

src/Symfony/Contracts/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-main": "3.4-dev"
28+
"dev-main": "3.5-dev"
2929
},
3030
"thanks": {
3131
"name": "symfony/contracts",

src/Symfony/Contracts/Deprecation/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-main": "3.4-dev"
28+
"dev-main": "3.5-dev"
2929
},
3030
"thanks": {
3131
"name": "symfony/contracts",

src/Symfony/Contracts/EventDispatcher/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"extra": {
2727
"branch-alias": {
28-
"dev-main": "3.4-dev"
28+
"dev-main": "3.5-dev"
2929
},
3030
"thanks": {
3131
"name": "symfony/contracts",

src/Symfony/Contracts/HttpClient/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-main": "3.4-dev"
30+
"dev-main": "3.5-dev"
3131
},
3232
"thanks": {
3333
"name": "symfony/contracts",

0 commit comments

Comments
 (0)