Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 25e8d7d

Browse filesBrowse files
committed
feature #40384 [DependencyInjection] Implement psr/container 1.1 (derrabus)
This PR was merged into the 5.3-dev branch. Discussion ---------- [DependencyInjection] Implement psr/container 1.1 | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A The `psr/container` interfaces have been updated with type declarations. The lack of those is what kept us from adding property type declarations to the `get()` and `has()` methods of our own `ContainerInterface`. A small BC break is that we have never prevented calling code from passing `null` as the service ID. Even without strict types, this will cause a `TypeError` after my changes. I already had to update `AutowirePass` because of that. On the other hand, it was neither documented that we allow `null` here nor did the container do anything useful (`has(null)` always resulted in `false` and `get(null)` always returned `null`). Commits ------- d9095aa [DependencyInjection] Implement psr/container 1.1
2 parents 94b8e32 + d9095aa commit 25e8d7d
Copy full SHA for 25e8d7d

File tree

8 files changed

+14
-16
lines changed
Filter options

8 files changed

+14
-16
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public function set(string $id, $service)
9393
/**
9494
* {@inheritdoc}
9595
*/
96-
public function has($id): bool
96+
public function has(string $id): bool
9797
{
9898
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
9999
}
100100

101101
/**
102102
* {@inheritdoc}
103103
*/
104-
public function get($id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
104+
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
105105
{
106106
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
107107
}

‎src/Symfony/Component/DependencyInjection/Container.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Container.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function set(string $id, ?object $service)
192192
*
193193
* @return bool true if the service is defined, false otherwise
194194
*/
195-
public function has($id)
195+
public function has(string $id)
196196
{
197197
if (isset($this->aliases[$id])) {
198198
$id = $this->aliases[$id];
@@ -221,7 +221,7 @@ public function has($id)
221221
*
222222
* @see Reference
223223
*/
224-
public function get($id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
224+
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
225225
{
226226
return $this->services[$id]
227227
?? $this->services[$id = $this->aliases[$id] ?? $id]

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,8 @@ public function removeDefinition(string $id)
517517
*
518518
* @return bool true if the service is defined, false otherwise
519519
*/
520-
public function has($id)
520+
public function has(string $id)
521521
{
522-
$id = (string) $id;
523-
524522
return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
525523
}
526524

@@ -539,9 +537,9 @@ public function has($id)
539537
*
540538
* @see Reference
541539
*/
542-
public function get($id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
540+
public function get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
543541
{
544-
if ($this->isCompiled() && isset($this->removedIds[$id = (string) $id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
542+
if ($this->isCompiled() && isset($this->removedIds[$id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
545543
return parent::get($id);
546544
}
547545

‎src/Symfony/Component/DependencyInjection/ContainerInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerInterface.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function set(string $id, ?object $service);
4848
*
4949
* @see Reference
5050
*/
51-
public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
51+
public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
5252

5353
/**
5454
* Returns true if the given service is defined.
@@ -57,7 +57,7 @@ public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFER
5757
*
5858
* @return bool true if the service is defined, false otherwise
5959
*/
60-
public function has($id);
60+
public function has(string $id);
6161

6262
/**
6363
* Check for whether or not a service has been initialized.

‎src/Symfony/Component/DependencyInjection/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20-
"psr/container": "^1.0",
20+
"psr/container": "^1.1.1",
2121
"symfony/deprecation-contracts": "^2.1",
2222
"symfony/polyfill-php80": "^1.15",
2323
"symfony/service-contracts": "^1.1.6|^2"

‎src/Symfony/Contracts/Service/ServiceLocatorTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Service/ServiceLocatorTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(array $factories)
4343
*
4444
* @return bool
4545
*/
46-
public function has($id)
46+
public function has(string $id)
4747
{
4848
return isset($this->factories[$id]);
4949
}
@@ -53,7 +53,7 @@ public function has($id)
5353
*
5454
* @return mixed
5555
*/
56-
public function get($id)
56+
public function get(string $id)
5757
{
5858
if (!isset($this->factories[$id])) {
5959
throw $this->createNotFoundException($id);

‎src/Symfony/Contracts/Service/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Service/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20-
"psr/container": "^1.0"
20+
"psr/container": "^1.1"
2121
},
2222
"suggest": {
2323
"symfony/service-implementation": ""

‎src/Symfony/Contracts/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"psr/cache": "^1.0|^2.0|^3.0",
21-
"psr/container": "^1.0",
21+
"psr/container": "^1.1",
2222
"psr/event-dispatcher": "^1.0"
2323
},
2424
"require-dev": {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.