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",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\Contracts\Service;
13+
14+
/**
15+
* A ServiceProviderInterface that is also countable and iterable.
16+
*
17+
* @author Kevin Bond <kevinbond@gmail.com>
18+
*
19+
* @template-covariant T of mixed
20+
*
21+
* @extends ServiceProviderInterface<T>
22+
* @extends \IteratorAggregate<string, T>
23+
*/
24+
interface ServiceCollectionInterface extends ServiceProviderInterface, \Countable, \IteratorAggregate
25+
{
26+
}

src/Symfony/Contracts/Service/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"minimum-stability": "dev",
3232
"extra": {
3333
"branch-alias": {
34-
"dev-main": "3.4-dev"
34+
"dev-main": "3.5-dev"
3535
},
3636
"thanks": {
3737
"name": "symfony/contracts",

src/Symfony/Contracts/Translation/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",

src/Symfony/Contracts/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"minimum-stability": "dev",
4646
"extra": {
4747
"branch-alias": {
48-
"dev-main": "3.4-dev"
48+
"dev-main": "3.5-dev"
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)