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

Allow extending#[When] attribute#47196

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:6.2fromruudk:instance-of-when
Aug 5, 2022
Merged

Conversation

@ruudk
Copy link
Contributor

@ruudkruudk commentedAug 5, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#46643
LicenseMIT
Doc PR

This allows people to extend the#[When] attribute with something like this:

namespaceApp\Symfony;useAttribute;useSymfony\Component\DependencyInjection\Attribute\When;#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::TARGET_FUNCTION | Attribute::IS_REPEATABLE)]finalclass Excludeextends When{publicfunction__construct()    {parent::__construct('never');    }}

Then they can use#[Exclude] instead of#[When(env: 'never')].

Or they can create#[ProductionOnly] instead of#[When(env: 'prod')].

I hoped that#46655 would be merged but it turns out that is not going to happen.

References:

RobVermeer reacted with thumbs up emoji
@derrabus
Copy link
Member

I like that change. Please add tests though.

This allows people to extend the When attribute with something like this:```phpuse Attribute;use Symfony\Component\DependencyInjection\Attribute\When;#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::TARGET_FUNCTION | Attribute::IS_REPEATABLE)]final class Exclude extends When{    public function __construct()    {        parent::__construct('never');    }}```Then they can use `#[Exclude]` instead of `#[When(env: 'never')]`.References:-symfony#46643-symfony#46655
@ruudk
Copy link
ContributorAuthor

@derrabus Done!

@fabpot
Copy link
Member

Thank you@ruudk.

@fabpotfabpot merged commite1435f6 intosymfony:6.2Aug 5, 2022
@ruudkruudk deleted the instance-of-when branchAugust 5, 2022 13:56
@fabpotfabpot mentioned this pull requestOct 24, 2022
ruudk added a commit to ruudk/symfony that referenced this pull requestJun 18, 2025
This allows people to extend the `#[AsAlias]` attribute with something like this:```phpnamespace App\Symfony;use Symfony\Component\DependencyInjection\Attribute\AsAlias;final class AsProductionAlias extends AsAlias{    /**     *@param string|null         $id     The id of the alias     *@param bool                $public Whether to declare the alias public     */    public function __construct(        public ?string $id = null,        public bool $public = false,    ) {        parent::__construct($id, $public, ['prod']);    }}```This is similar to a previous change I did for the `#[When]` attribute, that was accepted:-symfony#47196
nicolas-grekas added a commit that referenced this pull requestJun 18, 2025
…ribute (ruudk)This PR was squashed before being merged into the 7.4 branch.Discussion----------[DependencyInjection] Allow extending `#[AsAlias]` attribute| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        || License       | MITThis allows people to extend the `#[AsAlias]` attribute with something like this:```phpnamespace App\Symfony;use Symfony\Component\DependencyInjection\Attribute\AsAlias;final class AsProductionAlias extends AsAlias{    /**     * `@param` string|null         $id     The id of the alias     * `@param` bool                $public Whether to declare the alias public     */    public function __construct(        public ?string $id = null,        public bool $public = false,    ) {        parent::__construct($id, $public, ['prod']);    }}```This is similar to a previous change I did for the `#[When]` attribute, that was accepted:-#47196Commits-------90fd3ff [DependencyInjection] Allow extending `#[AsAlias]` attribute
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@derrabusderrabusderrabus approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

[DependencyInjection] Add attribute #[Exclude]

5 participants

@ruudk@derrabus@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp