Skip to content
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

Introduce Voter stub #326

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:
featureToggles:
skipCheckGenericClasses:
- Symfony\Component\OptionsResolver\Options
- Symfony\Component\Security\Core\Authorization\Voter\Voter
- Symfony\Component\Security\Core\User\PasswordUpgraderInterface
stubFiles:
- stubs/Psr/Cache/CacheItemInterface.stub
Expand Down Expand Up @@ -50,6 +51,7 @@ parameters:
- stubs/Symfony/Component/Security/Acl/Model/AclInterface.stub
- stubs/Symfony/Component/Security/Acl/Model/EntryInterface.stub
- stubs/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.stub
- stubs/Symfony/Component/Security/Core/Authorization/Voter/Voter.stub
- stubs/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.stub
- stubs/Symfony/Component/Security/Core/User/PasswordAuthenticatedUserInterface.stub
- stubs/Symfony/Component/Security/Core/User/PasswordUpgraderInterface.stub
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Symfony\Component\Security\Core\Authorization\Voter;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
* @template TAttribute of string
* @template TSubject of mixed
*/
abstract class Voter implements VoterInterface
{
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param mixed $subject
*
* @phpstan-assert-if-true TSubject $subject
* @phpstan-assert-if-true TAttribute $attribute
*
* @return bool
*/
abstract protected function supports(string $attribute, $subject);

/**
* Perform a single access check operation on a given attribute, subject and token.
* It is safe to assume that $attribute and $subject already passed the "supports()" method check.
*
* @phpstan-param TAttribute $attribute
* @phpstan-param TSubject $subject
*
* @return bool
*/
abstract protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token);
}