Skip to content

Commit 9f3b0b5

Browse files
derrabusnicolas-grekas
authored andcommitted
Add parameter type declarations to contracts.
1 parent 7491a93 commit 9f3b0b5

6 files changed

+8
-24
lines changed

Debug/TraceableEventDispatcher.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020
use Symfony\Component\Stopwatch\Stopwatch;
21-
use Symfony\Contracts\EventDispatcher\Event;
2221
use Symfony\Contracts\Service\ResetInterface;
2322

2423
/**
@@ -129,12 +128,8 @@ public function hasListeners(string $eventName = null)
129128
/**
130129
* {@inheritdoc}
131130
*/
132-
public function dispatch($event, string $eventName = null): object
131+
public function dispatch(object $event, string $eventName = null): object
133132
{
134-
if (!\is_object($event)) {
135-
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
136-
}
137-
138133
$eventName = $eventName ?? \get_class($event);
139134

140135
if (null === $this->callStack) {
@@ -143,7 +138,7 @@ public function dispatch($event, string $eventName = null): object
143138

144139
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
145140

146-
if (null !== $this->logger && ($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
141+
if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
147142
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
148143
}
149144

Debug/WrappedListener.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1616
use Symfony\Component\Stopwatch\Stopwatch;
1717
use Symfony\Component\VarDumper\Caster\ClassStub;
18-
use Symfony\Contracts\EventDispatcher\Event;
1918

2019
/**
2120
* @author Fabien Potencier <fabien@symfony.com>
@@ -121,7 +120,7 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf
121120
$e->stop();
122121
}
123122

124-
if (($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
123+
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
125124
$this->stoppedPropagation = true;
126125
}
127126
}

EventDispatcher.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\EventDispatcher\StoppableEventInterface;
1515
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
16-
use Symfony\Contracts\EventDispatcher\Event;
1716

1817
/**
1918
* The EventDispatcherInterface is the central point of Symfony's event listener system.
@@ -46,12 +45,8 @@ public function __construct()
4645
/**
4746
* {@inheritdoc}
4847
*/
49-
public function dispatch($event, string $eventName = null): object
48+
public function dispatch(object $event, string $eventName = null): object
5049
{
51-
if (!\is_object($event)) {
52-
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
53-
}
54-
5550
$eventName = $eventName ?? \get_class($event);
5651

5752
if (null !== $this->optimized && null !== $eventName) {
@@ -226,7 +221,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
226221
*/
227222
protected function callListeners(iterable $listeners, string $eventName, object $event)
228223
{
229-
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
224+
$stoppable = $event instanceof StoppableEventInterface;
230225

231226
foreach ($listeners as $listener) {
232227
if ($stoppable && $event->isPropagationStopped()) {

EventDispatcherInterface.php

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
*/
2323
interface EventDispatcherInterface extends ContractsEventDispatcherInterface
2424
{
25-
/**
26-
* {@inheritdoc}
27-
*/
28-
public function dispatch($event, string $eventName = null): object;
29-
3025
/**
3126
* Adds an event listener that listens on the specified events.
3227
*

ImmutableEventDispatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(EventDispatcherInterface $dispatcher)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function dispatch($event, string $eventName = null): object
31+
public function dispatch(object $event, string $eventName = null): object
3232
{
3333
return $this->dispatcher->dispatch($event, $eventName);
3434
}

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.9",
20-
"symfony/event-dispatcher-contracts": "^1.1|^2"
20+
"symfony/event-dispatcher-contracts": "^2"
2121
},
2222
"require-dev": {
2323
"symfony/dependency-injection": "^4.4|^5.0",
@@ -33,7 +33,7 @@
3333
},
3434
"provide": {
3535
"psr/event-dispatcher-implementation": "1.0",
36-
"symfony/event-dispatcher-implementation": "1.1"
36+
"symfony/event-dispatcher-implementation": "2.0"
3737
},
3838
"suggest": {
3939
"symfony/dependency-injection": "",

0 commit comments

Comments
 (0)