Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DI] Implement PSR-11#21265
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[DI] Implement PSR-11#21265
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| * @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
| */ | ||
| interface ContainerInterface | ||
| interface ContainerInterfaceextends PsrContainerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I chose to haveContainerInterface extendPsrContainerInterface, so that any interface is marked as psr-compliant. Not sure it is the right thing to do though, because php cannot enforce all the contracts defined in the interface docs (like what exception to throw when). Tell me if you feel I should remove this and addimplements ContainerInterface in the main implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If it works for PHP, fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
that basically means in whole framework you will not usePsr version, butSymfony version.
Then, one will be able to use concrete class that implementsSymfony version as parameter for method expectingPsr version, but not the other way around. So, if I will have some package that followsPsr, I won't be able to use it directly in Symfony project, because everywhere the framework will requireSymfony version instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
everywhere the framework will require Symfony
Not sure I get what you mean, but IMO once this is merged, we should hunt for theSymfony version everywhere, see what calls are made there, and if we can replace usePsr version as type hinting there.
nicolas-grekasJan 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@greg0ire without breaking BC, with the benefit of reducing the feature-set for the shake of PSR11 compliance? I doubt this is ever going to happen...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@jvasseur yes it does
the issue is that$foo instanceof A implies that calling$foo->test($anotherInstanceOfA) is allowed.
Since$anInstanceofB instanceof A, calling$anInstanceofB->test($anotherInstanceOfAButNotB) must thus be allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
So… I found a bug in php?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It's a know limitation of the PHP engine :https://bugs.php.net/bug.php?id=69612#1431343525
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
But your example is wrong anyway, functions parameters could be contravariant (they are invariant in PHP) meaning they can accept a wider type. In your example they are covariant instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Oh you're right, my logic was wrong indeed! Which means this would indeed be a BC-break, sorry I got confused.
| * @author Bulat Shakirzyanov <bulat@theopenskyproject.com> | ||
| */ | ||
| class InvalidArgumentExceptionextends \InvalidArgumentExceptionimplements ExceptionInterface | ||
| class InvalidArgumentExceptionextends \InvalidArgumentExceptionimplements ExceptionInterface, ContainerException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
EnvNotFound extends this exception, so no need to add implementation declaration in it.
greg0ire commentedJan 12, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
About "the mandatory NotFoundExceptionInterface on non-existing service problem", throwing an exception on missing service id is optional in the current implementation while mandatory in the PSR. How should we solve this problem? I was thinking we could deprecate the second argument of |
| "require": { | ||
| "php":">=5.5.9" | ||
| "php":">=5.5.9", | ||
| "psr/container":"^1.0@dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
add also provide sectionhttps://getcomposer.org/doc/04-schema.md#provide , like inhttps://github.com/Seldaek/monolog/blob/master/composer.json#L52-L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
See TODO list ;) , I'm not sure to be able to implement it perfectly, so first, let's get as close as we can without a BC-break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Still please add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Fine 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks like it should also be added to the rootcomposer.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Uuuuh… it's already there, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Indeed... I missed it 😳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for reviewing anyway :)
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There is no issue with throwing : the PSR standardize only one argument, and says to throw. Fortunately that's the default behavior so anyone using the container in the PSR11 way will have it work as expected.
When the 2nd argument is used, we're not in PSR11 anymore, thus we can behave as we want.
| * @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
| */ | ||
| interface ContainerInterface | ||
| interface ContainerInterfaceextends PsrContainerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If it works for PHP, fine.
| "require": { | ||
| "php":">=5.5.9" | ||
| "php":">=5.5.9", | ||
| "psr/container":"^1.0@dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Still please add it.
greg0ire commentedJan 12, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Makes sense. We can't hurt people that don't know which implementation they are using, because if they don't they will probably not risk calling |
composer.json Outdated
| "doctrine/common":"~2.4", | ||
| "twig/twig":"~1.28|~2.0", | ||
| "psr/cache":"~1.0", | ||
| "psr/container":"^1.0@dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Just reminder comment: Remove@dev annotation when the package will be stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we remove it now so that this PR is ready to be merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fixed
mnapoli commentedJan 13, 2017
👍 the interface was designed to be compatible with Symfony's default behavior when called with the PSR signature. |
greg0ire commentedJan 13, 2017
I did not read the underlying discussions for this spec but there definitely was a "well this is convenient" feeling when implementing it in Symfony 😄 |
dunglas commentedJan 13, 2017
It looks only small changes are required, nice! |
greg0ire commentedJan 13, 2017
@dunglas yup, that was a breeze :) |
nicolas-grekas commentedJan 13, 2017
RuntimeException also isn't it? |
nicolas-grekas commentedJan 13, 2017
Why not make ExceptionInterface extend Psr\Container\ContainerExceptionInterface? |
greg0ire commentedJan 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Only exceptions thrown directly by the container are supposed to implement this, so I only applied it to exceptions listedhere This meansthis is an issue doesn't it ? Should I changethis line so that the exception thrown here is wrapped into another? |
greg0ire commentedJan 13, 2017
Can't find it in Container.php, so no. |
nicolas-grekas commentedJan 13, 2017
nicolas-grekas commentedJan 13, 2017
I suggest to play simpe here. We don't care to add the interface on all exceptions. This wouldn't hurt. |
greg0ire commentedJan 13, 2017
Yeah but :
What does "directly" mean here? |
nicolas-grekas commentedJan 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't know in fact, and that's a good question! |
greg0ire commentedJan 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Very true, plus, less code, so… I'll change that.@mnapoli , can you advise about the meaning of "directly" here though? You know, for science? |
greg0ire commentedJan 13, 2017
There. The diff is tiny now :) |
greg0ire commentedJan 13, 2017
@nicolas-grekas what about this? Any thoughts? |
dunglas commentedFeb 8, 2017
👍 |
javiereguiluz left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍
fabpot commentedFeb 8, 2017
Thank you@greg0ire. |
This PR was merged into the 3.3-dev branch.Discussion----------[DI] Implement PSR-11TODO:- [x] wait for a stable version of the psr/container package;- [x] ~~deprecate instanciating ServiceNotFoundException directly, or using any of its methods directly;~~ not relevant anymore- [x] act on the outcome ofphp-fig/container#8 (solved inphp-fig/container#9) ;- [x] ~~solve the mandatory NotFoundExceptionInterface on non-existing serviceproblem (with a flag ?);~~ non-issue, see comments below- [x] provide meta-package psr/container-implementation if all problems canbe solved.| Q | A| ------------- | ---| Branch? | master| New feature? | yes| BC breaks? | not at the moment| Tests pass? | didn't pass before pushing, or even starting to code, will see Travis| License | MIT| Doc PR | TODOThis PR is a first attempt at implementing PSR-11, or at least trying to get closer to it.Delegate lookup is optional, and thus not implemented for now.Commits-------bde0efd Implement PSR-11
greg0ire commentedFeb 8, 2017
Thanks for merging! |
allflame commentedJun 7, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Can you please consider BC breaks not only with respect to "implementation" but also to "declaration"? And that's what happened: Your interfaces are your burden as much as your implementation. |
greg0ire commentedJun 7, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@allflame can't reproduce :https://3v4l.org/gNuOY |
jvasseur commentedJun 7, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@greg0ire you have to change the order of the implemented interfaces :https://3v4l.org/032Sk It's a know PHP bug. EDIT: here is the bugs.php.net reference :https://bugs.php.net/bug.php?id=63816 |
greg0ire commentedJun 7, 2017
Oh ok... well sorry, but I didn't know that bug. |
xabbuh commentedJun 8, 2017
Which class should be affected by that? This PR did not change any class to implement two interfaces, did it? |
greg0ire commentedJun 8, 2017
@xabbuh classes outside Symfony that happen to implement |
xabbuh commentedJun 8, 2017
Hm yeah, nothing we can account for here. This needs to be changed in those projects or fixed in PHP. |
allflame commentedJun 8, 2017
@xabbuh this "bug" is like 5 years old and since it just a consequence of OOP implementation in PHP it won't likely be "fixed" for another 5 years. My message here is the following: changes in "contracts/definitions" (that is interfaces, inheritance, function declaration etc) have way more potential to break things than changes in the "implementation" (e.g. actual code) |
stof commentedJun 8, 2017
Well, this means that we would have to avoid providing a PSR-11 compliant container because someone might have already built an external project implementing both PSR-11 and our interface ? This means we would never be able to implement PSR on existing code outside major versions. Btw, our BC promise explicitly mentions that wedon't ensure BC if you add new methods in a child class (as this would then forbid us to add any method in our existing classes due to potential signature mismatches for the child class using the name already). Adding extra interfaces on the class generally involve adding such method (PSR-11 actually may not need it though) |
allflame commentedJun 8, 2017
@stof Yes, this is what software versioning, BC and PHP imply. |
stof commentedJun 8, 2017
Well, are you actually implementing the Symfony ContainerInterface from scratch without using our base classes ? |
allflame commentedJun 8, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No, of course not. |
Uh oh!
There was an error while loading.Please reload this page.
TODO:
deprecate instanciating ServiceNotFoundException directly, or using any of its methods directly;not relevant anymoresolve the mandatory NotFoundExceptionInterface on non-existing servicenon-issue, see comments belowproblem (with a flag ?);
be solved.
This PR is a first attempt at implementing PSR-11, or at least trying to get closer to it.
Delegate lookup is optional, and thus not implemented for now.