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] fix definition and usage of AbstractArgument#36545

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
fabpot merged 1 commit intosymfony:masterfromnicolas-grekas:fix-abargs
Apr 24, 2020

Conversation

nicolas-grekas
Copy link
Member

QA
Branch?master
Bug fix?yes
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

Readinghttps://symfony.com/blog/new-in-symfony-5-1-abstract-service-arguments and the comments there made me realize that the current implementation is not generic enough. Abstract arguments can be found anywhere, not only as service arguments. Also,AbstractArgument instances should not convey the key/id since that makes them harder to use in the PHP-DSL.

@javiereguiluz
Copy link
Member

javiereguiluz commentedApr 23, 2020
edited
Loading

Thanks for simplifying this feature. This is thebefore:

<serviceid="maker.generator"class="Symfony\Bundle\MakerBundle\Generator">    <argumenttype="service"id="maker.file_manager" />    <argumenttype="abstract"key="$rootNamespace">defined in MakerPass</argument></service>
maker.generator:class:Symfony\Bundle\MakerBundle\Generatorarguments:$rootNamespace:!abstract defined in MakerPass
$builder->register('maker.generator', Generator::class)    ->addArgument(newAbstractArgument('maker.generator','$rootNamespace','defined in MakerPass'));

Could you please show theafter config? Thanks!

@nicolas-grekas
Copy link
MemberAuthor

before:
->addArgument(new AbstractArgument('foo', '$baz', 'should be defined by Pass'));

after:
->addArgument(new AbstractArgument('should be defined by Pass'));

the rest is untouched.

But the example in PHP should be this actually if we want the equivalent of yaml/xml:
->setArgument('$rootNamespace', new AbstractArgument('should be defined by Pass'));

@wouterj
Copy link
Member

wouterj commentedApr 23, 2020
edited
Loading

So I used this feature in the Security PR (see e.g.https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/SecurityBundle/Resources/config/security_authenticator.xml#L17) as<argument type="abstract">provider key</argument>.
Should we replace it with<argument type="abstract" key="$providerKey"/>? And then, if I'm correct we can no longer usereplaceArgument(1, $providerKey), but need to doreplaceArgument('$providerKey', $providerKey)?

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedApr 23, 2020
edited by chalasr
Loading

Should we replace it with<argument type="abstract" key="$providerKey"/>?

nope: we don't use named arguments in core

And then, if I'm correct we can no longer usereplaceArgument(1, $providerKey), but need to doreplaceArgument('$providerKey', $providerKey)?

nothing changes here (but this is argument 3, not 1)

@wouterj
Copy link
Member

wouterj commentedApr 23, 2020
edited
Loading

Hmm, but then I think this feature might still not be generic enough (or at least, it doesn't fit Symfony's usage). If I read the code correctly, the XML currently used in Security will result in this error message:
Argument "3" of service "security.authenticator.manager" is abstract. provider key.

This is imho weird in 2 ways:

  1. provider key. is a bit lost. The solution would be to only use<argument type="abstract"/>, but that removes the usefull explanation of what the argument will contain.
  2. It's not actually the 3rd argument that is missing, it's the 4th argument (but arguments are zero-indexed in the DI component).

(Btw, I agree with the changes in this PR, but I feel like the feature itself is not 100% correct yet)

@nicolas-grekas
Copy link
MemberAuthor

The message would be:
Argument "3" of service "security.authenticator.manager" is abstract: provider key.

I get what you mean@wouterj, but I don't have any better proposal.

@nicolas-grekas
Copy link
MemberAuthor

Note that what matters is that the message is actionable. In this regard, I think it is.

@nicolas-grekas
Copy link
MemberAuthor

Argument "3" of service "security.authenticator.manager" is abstract: provider key.

Updated to use positional numbers: Argument 4 of service "security.authenticator.manager" is abstract: provider key.

@fabpot
Copy link
Member

@javiereguiluz Can you update the blog post?

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@javiereguiluz
Copy link
Member

Yes! I've just updated the blog post 👍

@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
@fabpotfabpot mentioned this pull requestMay 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

5 participants
@nicolas-grekas@javiereguiluz@wouterj@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp