8000 [Security][SecurityBundle] Add messages and score on votes by eltharin · Pull Request #58107 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security][SecurityBundle] Add messages and score on votes #58107

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

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review corrections
  • Loading branch information
eltharin committed Feb 10, 2025
commit 1caecb5806974c00874f2003b3327bf921ce86a9
9 changes: 6 ad 8000 ditions & 3 deletions src/Symfony/Component/Security/Core/Authorization/AccessDecision.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
final class AccessDecision
{
/**
* @param int $access One of the VoterInterface::ACCESS_* constants
* @param int $access One of the VoterInterface constants (ACCESS_GRANTED, ACCESS_ABSTAIN, ACCESS_DENIED)
* @param Vote[] $votes
*/
public function __construct(private readonly int $access, private readonly array $votes = [], private readonly string $message = '')
{
public function __construct(
private readonly int $access,
private readonly array $votes = [],
private readonly string $message = '',
) {
}

public function getAccess(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ class Vote implements VoteInterface
private array $messages;

/**
* @param int $access One of the VoterInterface::ACCESS_* constants if scoring is false
* @param int $access One of the VoterInterface constants (ACCESS_GRANTED, ACCESS_ABSTAIN, ACCESS_DENIED)
* or an integer when scoring is false
*/
public function __construct(private int $access, string|array $messages = [], private array $context = [], private $scoring = false)
{
public function __construct(
private int $access,
string|array $messages = [],
private array $context = [],
private $scoring = false,
) {
if (!$scoring && !\in_array($access, [VoterInterface::ACCESS_GRANTED, VoterInterface::ACCESS_ABSTAIN, VoterInterface::ACCESS_DENIED], true)) {
throw new \LogicException(\sprintf('"$access" must return one of "%s" constants ("ACCESS_GRANTED", "ACCESS_DENIED" or "ACCESS_ABSTAIN") when "$scoring" is false, "%s" returned.', VoterInterface::class, $access));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
namespace Symfony\Component\Security\Core\Authorization\Voter;

/**
* A VoteInterface Object contain information about vote, access/score, messages.
* A VoteInterface object contain information about vote, access/score, messages.
*
* @author Roman JOLY <eltharin18@outlook.fr>
*/
interface VoteInterface
{
public function __construct(int $access, string|array $messages = [], array $context = []);

public function __debugInfo(): array;

public function getAccess(): int;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Security/Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CHANGELOG
* Add `$token` argument to `UserCheckerInterface::checkPostAuth()`
* Deprecate argument `$secret` of `RememberMeToken`
* Deprecate returning an empty string in `UserInterface::getUserIdentifier()`
* Add the ability for voter to return decision reason and a score by passing a Vote object
* Add the ability for voter to return decision reason and a score by passing a `Vote` object

7.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public function setAccessDecision(AccessDecision $accessDecision): void
}
}

/**
* Gets the access decision.
*/
public function getAccessDecision(): ?AccessDecision
{
return $this->accessDecision;
Expand Down
0