Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

[DI] Enhance DX by throwing instead of triggering a deprecation notice#22185

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

Merged
nicolas-grekas merged 1 commit intosymfony:masterfromnicolas-grekas:di-throw
Mar 28, 2017

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedMar 27, 2017
edited
Loading

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?yes - at the config file level, for edge cases
Deprecations?no
Tests pass?yes
Fixed tickets#22143
LicenseMIT
Doc PR-

Looking at the linked issue, I'm reconsidering our decision to trigger a deprecation notice when one uses_instanceof or_defaults as a service name. While on the BC side, this is strict - on the DX side, it looks like this opens a trap where people fill fall into.

The same occurs to me with named args: instead of silently accepting invalid args as was the case before, let's throw to help DX when people do mistakes.

Last change in this PR: the complex logic required to force strings to be given as$id args intoReference orAlias makes no sense to me, especially considering that astring type hint on PHP7 willdo a string cast.

ro0NL, curry684, and sstok reacted with thumbs up emoji
@fabpot
Copy link
Member

👍

@ro0NL
Copy link
Contributor

ro0NL commentedMar 27, 2017
edited
Loading

Given the linked issue.. what about addingfactory anddeprecated to the defaults white list?

edit: while reading adding deprecated may sound weird.. but from a per-file perspective it could make sense to deprecate a bunch of services (old namespace?) at once.

@curry684
Copy link
Contributor

curry684 commentedMar 27, 2017
edited
Loading

I'm obviously in favor of the BC break here, as the case is just about too hypothetical to consider at all. It doesn't close#22143 though, just its symptoms. The real issue there is thefactory attribute not working.

what about adding factory and deprecated to the defaults white list

I'm surprised to discover thereis a whitelist. I was expecting evencalls just to get optimistically merged based on method name to be honest. Same goes for deprecated, it may not be terribly useful, but why disable it just because we can't think of a really good use case right now.

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedMar 27, 2017
edited
Loading

@curry684 yes, there is a whitelist. Many attributes make no sense as defaults. See#21071 for the discussion about it. You missed learning about that because you did not get the exception you were supposed to - and that would have told about it (fixed here.)

Allowing factory/whatever in "defaults" is another discussion. So to me, this closes your issue, and you should open another issue as a feat request (yes, I know your issue was about that also, but let's split things now that we learned there are two things, isn't it? :) )

Copy link
Member

@stofstof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

@nicolas-grekasnicolas-grekas merged commitb07da3d intosymfony:masterMar 28, 2017
nicolas-grekas added a commit that referenced this pull requestMar 28, 2017
…precation notice (nicolas-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Enhance DX by throwing instead of triggering a deprecation notice| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | yes - at the config file level, for edge cases| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#22143| License       | MIT| Doc PR        | -Looking at the linked issue, I'm reconsidering our decision to trigger a deprecation notice when one uses `_instanceof` or `_defaults` as a service name. While on the BC side, this is strict - on the DX side, it looks like this opens a trap where people fill fall into.The same occurs to me with named args: instead of silently accepting invalid args as was the case before, let's throw to help DX when people do mistakes.Last change in this PR: the complex logic required to force strings to be given as `$id` args into `Reference` or `Alias` makes no sense to me, especially considering that a `string` type hint on PHP7 will *do* a string cast.Commits-------b07da3d [DI] Enhance DX by throwing instead of triggering a deprecation notice
@nicolas-grekasnicolas-grekas deleted the di-throw branchMarch 28, 2017 08:57
@fabpotfabpot mentioned this pull requestMay 1, 2017
continue;
}
if ('' ===$key ||'$' !==$key[0]) {
thrownewInvalidArgumentException(sprintf('Invalid key "%s" found in arguments of method "%s" for service "%s": only integer or $named arguments are allowed.',$key,$method,$this->currentId));
Copy link
Contributor

@danrotdanrotMay 30, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks like I am running into this now: What do you understand under a named arg? What exact configuration is forbidden by this change?

Is it possible that this disallows something like this:

<argumentkey="string"type="collection">    <argumentkey="other_string">value</argument></argument>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the issue iskey=string on your top-level argument. Adding a key on an argument only makes sense inside a collection-argument (as it is then the key inside the array) or using a supported way of defining named arguments.

Previously, defining keys for top-level arguments was not detected early, and would be causing weird bugs for some features

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof approved these changes

+1 more reviewer

@danrotdanrotdanrot left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

7 participants

@nicolas-grekas@fabpot@ro0NL@curry684@danrot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp