Skip to content

Commit d7e94f7

Browse files
[Contracts][EventDispatcher] add EventDispatcherInterface to symfony/contracts and use it where possible
1 parent da0aa94 commit d7e94f7

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

Authentication/AuthenticationProviderManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function __construct(iterable $providers, bool $eraseCredentials = true)
5151
$this->eraseCredentials = $eraseCredentials;
5252
}
5353

54+
/**
55+
* @final since Symfony 4.3, the type-hint will be updated to the interface from symfony/contracts in 5.0
56+
*/
5457
public function setEventDispatcher(EventDispatcherInterface $dispatcher)
5558
{
5659
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

Authorization/Voter/TraceableVoter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

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

14-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1515
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1616
use Symfony\Component\Security\Core\Event\VoteEvent;
17+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1718

1819
/**
1920
* Decorates voter classes to send result events.
@@ -30,14 +31,14 @@ class TraceableVoter implements VoterInterface
3031
public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher)
3132
{
3233
$this->voter = $voter;
33-
$this->eventDispatcher = $eventDispatcher;
34+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
3435
}
3536

3637
public function vote(TokenInterface $token, $subject, array $attributes)
3738
{
3839
$result = $this->voter->vote($token, $subject, $attributes);
3940

40-
$this->eventDispatcher->dispatch('debug.security.authorization.vote', new VoteEvent($this->voter, $subject, $attributes, $result));
41+
$this->eventDispatcher->dispatch(new VoteEvent($this->voter, $subject, $attributes, $result), 'debug.security.authorization.vote');
4142

4243
return $result;
4344
}

Tests/Authorization/Voter/TraceableVoterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1615
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1716
use Symfony\Component\Security\Core\Authorization\Voter\TraceableVoter;
1817
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1918
use Symfony\Component\Security\Core\Event\VoteEvent;
19+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2020

2121
class TraceableVoterTest extends TestCase
2222
{
@@ -44,7 +44,7 @@ public function testVote()
4444
$eventDispatcher
4545
->expects($this->once())
4646
->method('dispatch')
47-
->with('debug.security.authorization.vote', new VoteEvent($voter, 'anysubject', ['attr1'], VoterInterface::ACCESS_DENIED));
47+
->with(new VoteEvent($voter, 'anysubject', ['attr1'], VoterInterface::ACCESS_DENIED), 'debug.security.authorization.vote');
4848

4949
$sut = new TraceableVoter($voter, $eventDispatcher);
5050
$result = $sut->vote($token, 'anysubject', ['attr1']);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"symfony/contracts": "^1.0"
20+
"symfony/contracts": "^1.1"
2121
},
2222
"require-dev": {
2323
"psr/container": "^1.0",

0 commit comments

Comments
 (0)