Skip to content

Support for psr/container:^2 in dependency-injection and service-contracts #42058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elazar opened this issue Jul 11, 2021 · 3 comments
Closed

Comments

@elazar
Copy link

elazar commented Jul 11, 2021

symfony/dependency-injection v5.3.3 is pinned to psr/container:^1.1.1.

symfony/service-contracts v2.4.0 is pinned to psr/container:^1.1.

psr/container:^2 is now available. The changes between v1 and v2 are technically BC-breaking and present a compatibility issue. As such, they should probably only be done in a major release. However, the actual code changes required are minor enough that upgrading won't require much effort in that regard. I'm happy to submit these changes as a formal PR if there's consensus on if / when to implement them.

service-contracts needs its composer.json file updated and a bool typehint added to ServiceLocatorTrait->has().

diff --git a/ServiceLocatorTrait.php b/ServiceLocatorTrait.php
index 74dfa43..21ff445 100644
--- a/ServiceLocatorTrait.php
+++ b/ServiceLocatorTrait.php
@@ -43,7 +43,7 @@ trait ServiceLocatorTrait
      *
      * @return bool
      */
-    public function has(string $id)
+    public function has(string $id): bool
     {
         return isset($this->factories[$id]);
     }
diff --git a/composer.json b/composer.json
index 353413f..57316ee 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
     ],
     "require": {
         "php": ">=7.2.5",
-        "psr/container": "^1.1"
+        "psr/container": "^^2"
     },
     "suggest": {
         "symfony/service-implementation": ""

dependency-injection needs its composer.json file updated and a bool typehint added to Container->has(), ContainerBuilder->has(), ContainerInterface->has(), and ParameterBag\ContainerBag->has().

diff --git a/composer.json b/composer.json
index 65777679..bd75a893 100644
--- a/composer.json
+++ b/composer.json
@@ -17,11 +17,21 @@
     ],
     "require": {
         "php": ">=7.2.5",
-        "psr/container": "^1.1.1",
+        "psr/container": "^2",
         "symfony/deprecation-contracts": "^2.1",
         "symfony/polyfill-php80": "^1.15",
diff --git a/Container.php b/Container.php
index f096c75c..0ed5829a 100644
--- a/Container.php
+++ b/Container.php
@@ -186,7 +186,7 @@ class Container implements ContainerInterface, ResetInterface
      *
      * @return bool true if the service is defined, false otherwise
      */
-    public function has(string $id)
+    public function has(string $id): bool
     {
         if (isset($this->aliases[$id])) {
             $id = $this->aliases[$id];
diff --git a/ContainerBuilder.php b/ContainerBuilder.php
index d8d356ad..f006df08 100644
--- a/ContainerBuilder.php
+++ b/ContainerBuilder.php
@@ -518,7 +518,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      *
      * @return bool true if the service is defined, false otherwise
      */
-    public function has(string $id)
+    public function has(string $id): bool
     {
         return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
     }
diff --git a/ContainerInterface.php b/ContainerInterface.php
index 97da9a72..8e5da8c7 100644
--- a/ContainerInterface.php
+++ b/ContainerInterface.php
@@ -53,7 +53,7 @@ interface ContainerInterface extends PsrContainerInterface
     /**
      * @return bool true if the service is defined, false otherwise
      */
-    public function has(string $id);
+    public function has(string $id): bool;
 
     /**
      * Check for whether or not a service has been initialized.
diff --git a/ParameterBag/ContainerBag.php b/ParameterBag/ContainerBag.php
index 025fdaf2..295f16b6 100644
--- a/ParameterBag/ContainerBag.php
+++ b/ParameterBag/ContainerBag.php
@@ -48,7 +48,7 @@ class ContainerBag extends FrozenParameterBag implements ContainerBagInterface
      *
      * @return bool
      */
-    public function has(string $name)
+    public function has(string $name): bool
     {
         return $this->container->hasParameter($name);
     }
@nicolas-grekas
Copy link
Member

See #41660 on the topic. We want to get there, but we're still looking for the smoothest path, if there is any...

@stof
Copy link
Member

stof commented Jul 12, 2021

@nicolas-grekas we will need to bump symfony/service-contracts to 3.0 requiring psr/container 2.0. Then, in 6.0, we can have symfony/dependency-injection supporting both versions of symfony/service-contracts (to ease migration).
And for packages consuming our interface (rather than implementing), we should support both versions of symfony/service-contracts too (maybe even in 5.4)

@nicolas-grekas
Copy link
Member

Fixed in #42088

derrabus added a commit that referenced this issue Jul 15, 2021
…rekas)

This PR was merged into the 6.0 branch.

Discussion
----------

[Contracts] add return types and bump to v3

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #42058
| License       | MIT
| Doc PR        | -

Commits
-------

44b1a7a [Contracts] add return types and bump to v3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants