10000 Rebase for 6.3 · symfony/symfony@f2a827b · GitHub
[go: up one dir, main page]

Skip to content

Commit f2a827b

Browse files
committed
Rebase for 6.3
1 parent b53c509 commit f2a827b

35 files changed

+138
-99
lines changed

UPGRADE-6.3.md

+12
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ Validator
9393

9494
* Implementing the `ConstraintViolationInterface` without implementing the `getConstraint()` method is deprecated
9595

96+
Security
97+
--------
98+
99+
* Add method `getDecision()` to `AccessDecisionStrategyInterface`
100+
* Deprecate `AccessDecisionStrategyInterface::decide()` in favor of `AccessDecisionStrategyInterface::getDecision()`
101+
* Add method `getVote()` to `VoterInterface`
102+
* Deprecate `VoterInterface::vote()` in favor of `AccessDecisionStrategyInterface::getVote()`
103+
* Deprecate returning `bool` from `Voter::voteOnAttribute()` (it must return a `Vote`)
104+
* Add method `getDecision()` to `AccessDecisionManagerInterface`
105+
* Deprecate `AccessDecisionManagerInterface::decide()` in favor of `AccessDecisionManagerInterface::getDecision()`
106+
* Add method `getDecision()` to `AuthorizationCheckerInterface`
107+
96108
Serializer
97109
----------
98110

src/Symfony/Bundle/SecurityBundle/Tests/EventListener/VoteListenerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testOnVoterVoteLegacy()
5050
$traceableAccessDecisionManager = $this
5151
->getMockBuilder(TraceableAccessDecisionManager::class)
5252
->disableOriginalConstructor()
53-
->setMethods(['addVoterVote'])
53+
->onlyMethods(['addVoterVote'])
5454
->getMock();
5555

5656
$traceableAccessDecisionManager

src/Symfony/Component/Security/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The CHANGELOG for version 5.4 and newer can be found in the security sub-package
2828
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
2929
* Deprecate `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
3030
* Deprecate `UserInterface::getUsername()` in favor of `getUserIdentifier()`
31-
* Add `PassportInterface:getBadges()`, implemented by `PassportTrait`
31+
* Add `PassportInterface:getBadges()`, implemented &by `PassportTrait`
3232
* [BC BREAK] Remove method `checkIfCompletelyResolved()` from `PassportInterface`, checking that passport badges are
3333
resolved is up to `AuthenticatorManager`
3434
* Deprecate class `User`, use `InMemoryUser` instead

src/Symfony/Component/Security/Core/Authorization/AccessDecision.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@
2222
*/
2323
final class AccessDecision
2424
{
25-
/** @var int One of the VoterInterface::ACCESS_* constants */
26-
private int $access;
27-
28-
/** @var Vote[] */
29-
private array $votes = [];
30-
3125
/**
3226
* @param int $access One of the VoterInterface::ACCESS_* constants
3327
* @param Vote[] $votes
3428
*/
35-
private function __construct(int $access, array $votes = [])
29+
private function __construct(private readonly int $access, private readonly array $votes = [])
3630
{
37-
$this->access = $access;
38-
$this->votes = $votes;
3931
}
4032

4133
public function getAccess(): int
@@ -111,8 +103,6 @@ public function getDeniedVotes(): array
111103
*/
112104
private function getVotesByAccess(int $access): array
113105
{
114-
return array_filter($this->votes, static function (Vote $vote) use ($access): bool {
115-
return $vote->getAccess() === $access;
116-
});
106+
return array_filter($this->votes, static fn (Vote $vote): bool => $vote->getAccess() === $access);
117107
}
118108
}

src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
*/
2828
final class AccessDecisionManager implements AccessDecisionManagerInterface
2929
{
30-
private const VALID_VOTES = [
31-
VoterInterface::ACCESS_GRANTED => true,
32-
VoterInterface::ACCESS_DENIED => true,
33-
VoterInterface::ACCESS_ABSTAIN => true,
34-
];
35-
3630
private iterable $voters;
3731
private array $votersCacheAttributes = [];
3832
private array $votersCacheObject = [];
@@ -70,11 +64,11 @@ public function getDecision(TokenInterface $token, array $attributes, mixed $obj
7064
/**
7165
* @param bool $allowMultipleAttributes Whether to allow passing multiple values to the $attributes array
7266
*
73-
* @deprecated since Symfony 6.2, use {@see getDecision()} instead.
67+
* @deprecated since Symfony 6.3, use {@see getDecision()} instead.
7468
*/
7569
public function decide(TokenInterface $token, array $attributes, mixed $object = null, bool $allowMultipleAttributes = false): bool
7670
{
77-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
71+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
7872

7973
// Special case for AccessListener, do not remove the right side of the condition before 6.0
8074
if (\count($attributes) > 1 && !$allowMultipleAttributes) {

src/Symfony/Component/Security/Core/Authorization/AccessDecisionManagerInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface AccessDecisionManagerInterface
2828
* @param array $attributes An array of attributes associated with the method being invoked
2929
* @param mixed $object The object to secure
3030
*
31-
* @deprecated since Symfony 6.2, use {@see getDecision()} instead.
31+
* @deprecated since Symfony 6.3, use {@see getDecision()} instead.
3232
*/
3333
public function decide(TokenInterface $token, array $attributes, mixed $object = null): bool;
3434
}

src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final public function getDecision($attribute, $subject = null): AccessDecision
5151
}
5252

5353
if (!method_exists($this->accessDecisionManager, 'getDecision')) {
54-
trigger_deprecation('symfony/security-core', '6.2', 'Not implementing "%s::getDecision()" method is deprecated, and would be required in 7.0.', \get_class($this->accessDecisionManager));
54+
trigger_deprecation('symfony/security-core', '6.3', 'Not implementing "%s::getDecision()" method is deprecated, and would be required in 7.0.', \get_class($this->accessDecisionManager));
5555

5656
return $this->accessDecisionManager->decide($token, [$attribute], $subject) ? AccessDecision::createGranted() : AccessDecision::createDenied();
5757
}

src/Symfony/Component/Security/Core/Authorization/Strategy/AccessDecisionStrategyInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface AccessDecisionStrategyInterface
2525
/**
2626
* @param \Traversable<int> $results
2727
*
28-
* @deprecated since Symfony 6.2, use {@see getDecision()} instead.
28+
* @deprecated since Symfony 6.3, use {@see getDecision()} instead.
2929
*/
3030
public function decide(\Traversable $results): bool;
3131
}

src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getDecision(\Traversable $votes): AccessDecision
6363

6464
public function decide(\Traversable $results): bool
6565
{
66-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
66+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
6767

6868
$deny = 0;
6969
foreach ($results as $result) {

src/Symfony/Component/Security/Core/Authorization/Strategy/ConsensusStrategy.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public function __construct(bool $allowIfAllAbstainDecisions = false, bool $allo
4444
$this->allowIfEqualGrantedDeniedDecisions = $allowIfEqualGrantedDeniedDecisions;
4545
}
4646

47-
/**
48-
* {@inheritdoc}
49-
*/
5047
public function getDecision(\Traversable $votes): AccessDecision
5148
{
5249
$currentVotes = [];
@@ -84,12 +81,9 @@ public function getDecision(\Traversable $votes): AccessDecision
8481
;
8582
}
8683

87-
/**
88-
* {@inheritdoc}
89-
*/
9084
public function decide(\Traversable $results): bool
9185
{
92-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
86+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
9387

9488
$grant = 0;
9589
$deny = 0;

src/Symfony/Component/Security/Core/Authorization/Strategy/PriorityStrategy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getDecision(\Traversable $votes): AccessDecision
5959

6060
public function decide(\Traversable $results): bool
6161
{
62-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
62+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
6363

6464
foreach ($results as $result) {
6565
if (VoterInterface::ACCESS_GRANTED === $result) {

src/Symfony/Component/Security/Core/Authorization/Strategy/UnanimousStrategy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getDecision(\Traversable $votes): AccessDecision
6464

6565
public function decide(\Traversable $results): bool
6666
{
67-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
67+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
6868

6969
$grant = 0;
7070
foreach ($results as $result) {

src/Symfony/Component/Security/Core/Authorization/TraceableAccessDecisionManager.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ public function getDecision(TokenInterface $token, array $attributes, mixed $obj
6767
return $result;
6868
}
6969

70-
/**
71-
* {@inheritdoc}
72-
*/
7370
public function decide(TokenInterface $token, array $attributes, mixed $object = null, bool $allowMultipleAttributes = false): bool
7471
{
75-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
72+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::decide()" has been deprecated, use "%s::getDecision()" instead.', __CLASS__, __CLASS__);
7673

7774
$currentDecisionLog = [
7875
'attributes' => $attributes,
@@ -100,7 +97,7 @@ public function decide(TokenInterface $token, array $attributes, mixed $object =
10097
public function addVoterVote(VoterInterface $voter, array $attributes, Vote|int $vote): void
10198
{
10299
if (!$vote instanceof Vote) {
103-
trigger_deprecation('symfony/security-core', '6.2', 'Passing an int as the third argument to "%s::addVoterVote()" is deprecated, pass an instance of "%s" instead.', __CLASS__, Vote::class);
100+
trigger_deprecation('symfony/security-core', '6.3', 'Passing an int as the third argument to "%s::addVoterVote()" is deprecated, pass an instance of "%s" instead.', __CLASS__, Vote::class);
104101
$vote = new Vote($vote);
105102
}
106103

src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
8787

8888
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
8989
{
90-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
90+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
9191

9292
return $this->getVote($token, $subject, $attributes)->getAccess();
9393
}

src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
7171

7272
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
7373
{
74-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
74+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
7575

7676
return $this->getVote($token, $subject, $attributes)->getAccess();
7777
}

src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
5050

5151
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
5252
{
53-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
53+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
5454

5555
return $this->getVote($token, $subject, $attributes)->getAccess();
5656
}

src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
4949

5050
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
5151
{
52-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
52+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
5353

5454
return $this->getVote($token, $subject, $attributes)->getAccess();
5555
}

src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
4949

5050
$decision = $this->voteOnAttribute($attribute, $subject, $token);
5151
if (\is_bool($decision)) {
52-
trigger_deprecation('symfony/security-core', '6.2', 'Returning a boolean in "%s::voteOnAttribute()" is deprecated, return an instance of "%s" instead.', static::class, Vote::class);
52+
trigger_deprecation('symfony/security-core', '6.3', 'Returning a boolean in "%s::voteOnAttribute()" is deprecated, return an instance of "%s" instead.', static::class, Vote::class);
5353
$decision = $decision ? $this->grant() : $this->deny();
5454
}
5555

@@ -58,8 +58,8 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
5858
return $decision;
5959
}
6060

61-
if ('' !== $decision->getMessage()) {
62-
$vote->addMessage($decision->getMessage());
61+
if ('' !== $decisionMessage = $decision->getMessage()) {
62+
$vote->addMessage($decisionMessage);
6363
}
6464
}
6565

@@ -68,7 +68,7 @@ public function getVote(TokenInterface $token, mixed $subject, array $attributes
6868

6969
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
7070
{
71-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
71+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::vote()" has been deprecated, use "%s::getVote()" instead.', __CLASS__, __CLASS__);
7272

7373
return $this->getVote($token, $subject, $attributes)->getAccess();
7474
}
@@ -140,7 +140,7 @@ abstract protected function supports(string $attribute, mixed $subject): bool;
140140
* @param TAttribute $attribute
141141
* @param TSubject $subject
142142
*
143-
* @return Vote|bool Returning a boolean is deprecated since Symfony 6.2. Return a Vote object instead.
143+
* @return Vote|bool Returning a boolean is deprecated since Symfony 6.3. Return a Vote object instead.
144144
*/
145145
abstract protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): Vote|bool;
146146
}

src/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* VoterInterface is the interface implemented by all voters.
1818
*
19-
* @author Fabien Potencier <fabien@symfony.com>*
19+
* @author Fabien Potencier <fabien@symfony.com>
2020
*
2121
* @method Vote getVote(TokenInterface $token, mixed $subject, array $attributes)
2222
*/
@@ -39,7 +39,7 @@ interface VoterInterface
3939
*
4040
* @psalm-return self::ACCESS_* must be transformed into @return on Symfony 7
4141
*
42-
* @deprecated since Symfony 6.2, use {@see getVote()} instead.
42+
* @deprecated since Symfony 6.3, use {@see getVote()} instead.
4343
*/
4444
public function vote(TokenInterface $token, mixed $subject, array $attributes);
4545
}

src/Symfony/Component/Security/Core/CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
CHANGELOG
22
=========
33

4+
6.3
5+
---
6+
7+
* Add method `getDecision()` to `AccessDecisionStrategyInterface`
8+
* Deprecate `AccessDecisionStrategyInterface::decide()` in favor of `AccessDecisionStrategyInterface::getDecision()`
9+
* Add method `getVote()` to `VoterInterface`
10+
* Deprecate `VoterInterface::vote()` in favor of `AccessDecisionStrategyInterface::getVote()`
11+
* Deprecate returning `bool` from `Voter::voteOnAttribute()` (it must return a `Vote`)
12+
* Add method `getDecision()` to `AccessDecisionManagerInterface`
13+
* Deprecate `AccessDecisionManagerInterface::decide()` in favor of `AccessDecisionManagerInterface::getDecision()`
14+
* Add method `getDecision()` to `AuthorizationCheckerInterface`
15+
* Add methods `setAccessDecision()` and `getAccessDecision()` to `AccessDeniedException`
16+
* Add method `getDecision()` to `Security`
17+
418
6.2
519
---
620

src/Symfony/Component/Security/Core/Event/VoteEvent.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(VoterInterface $voter, mixed $subject, array $attrib
3636
$this->attributes = $attributes;
3737

3838
if (!$vote instanceof Vote) {
39-
trigger_deprecation('symfony/security-core', '6.2', 'Passing an int as the fourth argument to "%s::__construct" is deprecated, pass a "%s" instance instead.', __CLASS__, Vote::class);
39+
trigger_deprecation('symfony/security-core', '6.3', 'Passing an int as the fourth argument to "%s::__construct" is deprecated, pass a "%s" instance instead.', __CLASS__, Vote::class);
4040

4141
$vote = new Vote($vote);
4242
}
@@ -59,11 +59,11 @@ public function getAttributes(): array
5959
}
6060

6161
/**
62-
* @deprecated since Symfony 6.2, use {@see getVoteDecision()} instead.
62+
* @deprecated since Symfony 6.3, use {@see getVoteDecision()} instead.
6363
*/
6464
public function getVote(): int
6565
{
66-
trigger_deprecation('symfony/security-core', '6.2', 'Method "%s::getVote()" has been deprecated, use "%s::getVoteDecision()" instead.', __CLASS__, __CLASS__);
66+
trigger_deprecation('symfony/security-core', '6.3', 'Method "%s::getVote()" has been deprecated, use "%s::getVoteDecision()" instead.', __CLASS__, __CLASS__);
6767

6868
return $this->vote->getAccess();
6969
}

src/Symfony/Component/Security/Core/Exception/AccessDeniedException.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AccessDeniedException extends RuntimeException
2525
{
2626
private array $attributes = [];
2727
private mixed $subject = null;
28-
private ?AccessDecision $accessDecision;
28+
private ?AccessDecision $accessDecision = null;
2929

3030
public function __construct(string $message = 'Access Denied.', \Throwable $previous = null)
3131
{
@@ -60,22 +60,18 @@ public function setSubject(mixed $subject)
6060

6161
/**
6262
* Sets an access decision and appends the denied reasons to the exception message.
63-
*
64-
* @return void
6563
*/
66-
public function setAccessDecision(AccessDecision $accessDecision)
64+
public function setAccessDecision(AccessDecision $accessDecision): void
6765
{
6866
$this->accessDecision = $accessDecision;
69-
if (!$accessDecision->getDeniedVotes()) {
67+
if (!$deniedVotes = $accessDecision->getDeniedVotes()) {
7068
return;
7169
}
7270

73-
$messages = array_map(static function (Vote $vote) {
74-
return $vote->getMessage();
75-
}, $accessDecision->getDeniedVotes());
71+
$messages = array_map(static fn (Vote $vote): string => sprintf('"%s"', $vote->getMessage()), $deniedVotes);
7672

7773
if ($messages) {
78-
$this->message .= ' '.implode(' ', $messages);
74+
$this->message .= sprintf(' Decision message%s %s', \count($messages) > 1 ? 's are' : ' is', implode(' and ', $messages));
7975
}
8076
}
8177

src/Symfony/Component/Security/Core/Test/AccessDecisionStrategyTestCase.php

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final public function testGetDecision(AccessDecisionStrategyInterface $strategy,
4141

4242
/**
4343
* @group legacy
44+
*
4445
* @dataProvider provideStrategyTests
4546
*
4647
* @param VoterInterface[] $voters
@@ -91,6 +92,11 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
9192
{
9293
return $this->vote;
9394
}
95+
96+
public function getVote(TokenInterface $token, mixed $subject, array $attributes): Vote
97+
{
98+
return new Vote($this->vote);
99+
}
94100
};
95101
}
96102
}

0 commit comments

Comments
 (0)
0