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

[Security] Add#[AsVoter] attribute to configure voter priority#62341

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

Open
ayyoub-afwallah wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromayyoub-afwallah:feature/add-asVoter-attribute

Conversation

@ayyoub-afwallah
Copy link

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#43074
LicenseMIT

Description

This PR introduces a new#[AsVoter] attribute that allows security voters to declare their priority directly within the class, as proposed in issue#43074.

Motivation

While#[AsTaggedItem] or#[Autoconfigure] can technically set voter priority, they require manually specifying tag names and options, making the configuration verbose, error-prone, and less intuitive.

The goal of#[AsVoter] is to simplify voter configuration and make it explicit, intuitive, and easy to use, following the pattern of other Symfony attributes such as#[AsEventListener].

The#[AsVoter] attribute provides:

  • Clearer intent: Explicitly designed for security voters
  • Better developer experience: More discoverable and easier to understand than generic tag configuration
  • Consistency: Aligns with other component-specific attributes like#[AsCommand],#[AsEventListener],#[AsMessageHandler], etc.
  • Foundation for future enhancements: Provides a dedicated attribute that can be extended with additional voter-specific configuration options in the future

Behavior

  • The attribute can be added once per class
  • The#[AsVoter] attribute overrides YAML configuration and other attributes (#[AsTaggedItem]#[Autoconfigure])
  • This ensures the in-class configuration is always respected

Before

// config/services.yamlservices:    App\Security\Voter\PostVoter:        tags:            - { name: security.voter, priority:100 }
useSymfony\Component\DependencyInjection\Attribute\AsTaggedItem;#[AsTaggedItem('security.voter', ['priority' =>100])]class PostVoterimplements VoterInterface{publicfunctionvote(TokenInterface$token,mixed$subject,array$attributes):int    {// ...    }}

After

useSymfony\Component\Security\Core\Attribute\AsVoter;#[AsVoter(priority:100)]class PostVoterimplements VoterInterface{publicfunctionvote(TokenInterface$token,mixed$subject,array$attributes):int    {// ...    }}

@ayyoub-afwallahayyoub-afwallahforce-pushed thefeature/add-asVoter-attribute branch from28fda6f to4fda52cCompareNovember 7, 2025 22:35
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

getDefaultPriority behavior not working with voter

2 participants

@ayyoub-afwallah@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp