Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33d14d0

Browse files
committed
[DependencyInjection] Add ServiceCollectionInterface
1 parent e85fa2c commit 33d14d0

File tree

13 files changed

+62
-11
lines changed

13 files changed

+62
-11
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
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

+11-3
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,10 @@
2626
*
2727
* @template-covariant T of mixed
2828
*
29-
* @implements ServiceProviderInterface<T>
29+
* @implements ServiceCollectionInterface<T>
30+
* @implements \IteratorAggregate<string, T>
3031
*/
31-
class ServiceLocator implements ServiceProviderInterface, \Countable
32+
class ServiceLocator implements ServiceCollectionInterface
3233
{
3334
use ServiceLocatorTrait {
3435
get as private doGet;
@@ -82,6 +83,13 @@ public function count(): int
8283
return \count($this->getProvidedServices());
8384
}
8485

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

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

+11
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

+1-1
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

+5
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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",
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 <[email protected]>
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 <[email protected]>
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

+1-1
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

+1-1
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

+1-1
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)