-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
WIP: Yii2 implements PSR-11 #14107
WIP: Yii2 implements PSR-11 #14107
Conversation
|
Will look into that.
…On May 4, 2017 9:00 AM, "Carsten Brandt" ***@***.***> wrote:
NotFoundExceptionInterface and ContainerExceptionInterface also need to
be considered to be compatible. There is more to it than just implementing
the interface:
https://github.com/php-fig/fig-standards/blob/
10bb43b1802c0427f8a4a5d1e6a84da83fa7724d/accepted/PSR-11-
container.md#12-exceptions
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14107 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAhYzfihRJ5DBbhD89F36hi8wWiUhQcpks5r2W7dgaJpZM4NPkJC>
.
|
the signatures are not the same either
and they do different things too. while i don't think psr-11 is for yii2 |
if it matches the spec of PSR-11 that is fine, it can do more but it must support what is defined in the PSR to be compatible to it. |
@samdark I'm working on this now.
However this is part of a path that is unreachable. All definitions are validated when they are set inside the container, so this seems like a redundant check on a private variable. Also, |
@Faryshta I think we're fine with respect to
While we support other argument types, users of the container will only pass in strings (since that is what the specs tell them to do), so other behavior is not relevant for them. |
watching it |
|
||
namespace yii\di; | ||
|
||
use \yii\base\InvalidConfigException as Base; |
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.
using Base as alias is not preferable. Using the full class name is better here
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.
Why not implement ContainerExceptionInterface
at yii\base\InvalidConfigException
after all, the init()
method on most classes throws that exception already.
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.
yii\base\InvalidConfigException
has a wider meaning - it refers to any mis-configuration error, which is not mandatory triggered by DI.
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? The PSR never says that only DI can throw said exceptions.
Besides as you say any configuration error will throw yii\base\InvalidConfigException
which by the PSR.
A call to the get method with a non-existing id MUST throw a Psr\Container\NotFoundExceptionInterface.
So $di->get('db', [/* invalid params or config */])
must throw Psr\Container\NotFoundExceptionInterface
composer.json
Outdated
@@ -78,7 +78,8 @@ | |||
"bower-asset/jquery": "2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", | |||
"bower-asset/jquery.inputmask": "~3.2.2 | ~3.3.3", | |||
"bower-asset/punycode": "1.3.*", | |||
"bower-asset/yii2-pjax": "~2.0.1" | |||
"bower-asset/yii2-pjax": "~2.0.1", | |||
"psr/container": "^1.0" |
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'd rather not pollute composer.json for such 'nice-to-have' features
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's fine. It's an interface and there's no other way to solve it rather than requiring 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.
true
Yes. |
What would extend PSR NotFoundExceptionInterface then? |
Overall signatures and behavior are compatible. I see no reason not to merge it. |
|
@samdark Could you check why the tests are not working? I've done a reinstall of Side note: do we really need |
Probably lock file is in damaged state. Delete it, re-run composer update (ideally w/ PHP 5.4) and commit changes. We need it to run code coverage and code analysis tools. They're not able to install global composer plugins. |
Where do i get PHP5.4? Wayback Machine? :-D This was originally a joke, I thought there would be an official docker image with PHP5.4.... Turns out I was wrong |
php.net :) I can take care of it. |
Okay, great, google gave me this docker image: https://github.com/alterway/docker-php/blob/master/doc-php-cli.md |
These would do as well. |
@samdark I have reinstalled all using a php 5.4 environment, still doesn't seem to be working. |
@samdark I give up; it seems the |
Locally I did. Container unit tests are giving errors... |
|
@cebe Can you double check the exception stuff? Note that |
Applying interface ContainerInterface
{
public function get($id)
} with: class Container extends Component
{
public function get($class ...)
{
}
} While during inheritance change of the method argument is allowed, it may end with E_STRICT error at some environment. We already have similar issues like #13538 about slight inconsistencies around method redeclaration, which can be spoted only in particular strict environment. To make things right signature of the class Container extends Component
{
public function get($id, $params = [], $config = [])
{
}
} which actually a BC break. |
@klimov-paul as far as I know the parameter name is different, the type is not. |
I can not say that current implementation of the At the present state of this PR |
@@ -16,7 +17,7 @@ | |||
* @author Sam Mousa <sam@mousa.nl> | |||
* @since 2.0.9 | |||
*/ | |||
class NotInstantiableException extends InvalidConfigException | |||
class NotInstantiableException extends InvalidConfigException implements NotFoundExceptionInterface |
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.
This does not seem to be appropriate: NotFoundExceptionInterface
means there is NO definition of the entity inside the container, while NotInstantiableException
means the definition is invalid, pointing to something, which can not be intantiated like interface or absract class.
These exeptions can not be made equal.
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.
The PSR does not have something for not instantiable.
|
||
namespace yii\di; | ||
|
||
use \yii\base\InvalidConfigException as Base; |
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.
yii\base\InvalidConfigException
has a wider meaning - it refers to any mis-configuration error, which is not mandatory triggered by DI.
Sorry, but I do not understand what are you referring to. |
I suggest applying PSR-11 to be performed at 2.1 branch in appropriate matter, including methods signature change, exception hierarchy revision and logic adjustments, instead of patching 2.0.x by all cost. |
I don't mind waiting for 2.1 for this, just not all your arguments are valid. It is fine to provide a container that has default definitions for ids that happen to be class names. That does not break the spec, it just means that the container is preconfigured. I wasn't aware that the name of an argument was relevant; if it is that's something that can be easily fixed of course. |
I agree that it makes sense to do the change in 2.1 where we can actually adjust semantics correctly, add features necessary and change method signatures. I'm closing the pull request. Let's use #14112 for future discussion. |
PSR-11 is accepted and Yii implements it.