Skip to content

[DependencyInjection] Resolve container parameter used in index attribute of service tags #54664

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

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

BreyndotEchse
Copy link
Contributor

@BreyndotEchse BreyndotEchse commented Apr 18, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Resolve tags' index attribute to allow the use of container parameters.

YAML config example:

parameters:
    foo.bar_reference1: !php/const:App\Service\Foo::EXAMPLE_REFERENCE1
    foo.bar_reference2: !php/const:App\Service\Foo::EXAMPLE_REFERENCE2

services:
    App\Service\Foo:
        tags:
            - { name: 'bar.reference', key: '%foo.bar_reference1%' }
            - { name: 'bar.reference', key: '%foo.bar_reference2%' }

    App\Service\Bar:
        arguments:
            - !tagged_locator { tag: 'bar.reference', index_by: 'key' }

XML config example:

<?xml version="1.0" encoding="UTF-8" ?>
<container [...]>
    <parameters>
        <parameter key="foo.bar_reference1" type="constant">App\Service\Foo::EXAMPLE_REFERENCE1</parameter>
        <parameter key="foo.bar_reference2" type="constant">App\Service\Foo::EXAMPLE_REFERENCE2</parameter>
    </parameters>

    <services>
        <service id="App\Service\Foo">
            <tag name="bar.reference" key="%foo.bar_reference1%" />
            <tag name="bar.reference" key="%foo.bar_reference2%" />
        </service>

        <service id="App\Service\Bar">
            <argument type="tagged_locator" tag="bar.reference" index-by="key" />
        </service>
    </services>
</container>

@carsonbot carsonbot added this to the 7.1 milestone Apr 18, 2024
@carsonbot carsonbot changed the title [DI] Resolve container parameter used in index attribute of service tags [DependencyInjection] Resolve container parameter used in index attribute of service tags Apr 18, 2024
@BreyndotEchse
Copy link
Contributor Author

Sorry guys, forgot about this PR and synced the fork... I didn't mean to request your review

@stof
Copy link
Member

stof commented Jun 19, 2024

@BreyndotEchse that's why you should better use dedicated branches for PRs rather than working directly in your forked branch (btw, this also allows having multiple PRs opened)

@valtzu
Copy link
Contributor

valtzu commented Aug 12, 2024

If one used environment variable parameter in the tag, would it be resolved build-time or runtime?

edit: must be build-time since tags don't exist runtime

@fabpot
Copy link
Member

fabpot commented Oct 6, 2024

Thank you @BreyndotEchse.

@fabpot fabpot merged commit 83beaba into symfony:7.2 Oct 6, 2024
9 of 10 checks passed
@fabpot fabpot mentioned this pull request Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants