Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3edb79f

Browse files
committed
feature symfony#30772 [Contracts][EventDispatcher] move the Event class to symfony/contracts (nicolas-grekas)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Contracts][EventDispatcher] move the Event class to symfony/contracts | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Will allow decoupling more components in 5.0 Commits ------- a4ce08e [Contracts][EventDispatcher] move the Event class to symfony/contracts
2 parents f4176b0 + a4ce08e commit 3edb79f

File tree

11 files changed

+114
-31
lines changed

11 files changed

+114
-31
lines changed

UPGRADE-4.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ EventDispatcher
4242
---------------
4343
4444
* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
45+
* The `Event` class has been deprecated, use `Symfony\Contracts\EventDispatcher\Event` instead
4546

4647
Form
4748
----

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ EventDispatcher
7171

7272
* The `TraceableEventDispatcherInterface` has been removed.
7373
* The signature of the `EventDispatcherInterface::dispatch()` method has been updated to `dispatch($event, string $eventName = null)`
74+
* The `Event` class has been removed, use `Symfony\Contracts\EventDispatcher\Event` instead
7475

7576
DependencyInjection
7677
-------------------

src/Symfony/Component/EventDispatcher/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
8+
* deprecated the `Event` class, use `Symfony\Contracts\EventDispatcher\Event` instead
89

910
4.1.0
1011
-----

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1919
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
2020
use Symfony\Component\Stopwatch\Stopwatch;
21+
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
2122

2223
/**
2324
* Collects some data about event listeners.
@@ -147,7 +148,7 @@ public function dispatch($event/*, string $eventName = null*/)
147148
}
148149
}
149150

150-
if (null !== $this->logger && ($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
151+
if (null !== $this->logger && ($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
151152
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
152153
}
153154

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1717
use Symfony\Component\Stopwatch\Stopwatch;
1818
use Symfony\Component\VarDumper\Caster\ClassStub;
19+
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
1920

2021
/**
2122
* @author Fabien Potencier <[email protected]>
@@ -123,7 +124,7 @@ public function __invoke(Event $event, $eventName, EventDispatcherInterface $dis
123124
$e->stop();
124125
}
125126

126-
if (($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
127+
if (($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
127128
$this->stoppedPropagation = true;
128129
}
129130
}

src/Symfony/Component/EventDispatcher/Event.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,24 @@
1212
namespace Symfony\Component\EventDispatcher;
1313

1414
/**
15-
* Event is the base class for classes containing event data.
16-
*
17-
* This class contains no event data. It is used by events that do not pass
18-
* state information to an event handler when an event is raised.
19-
*
20-
* You can call the method stopPropagation() to abort the execution of
21-
* further listeners in your event listener.
22-
*
23-
* @author Guilherme Blanco <[email protected]>
24-
* @author Jonathan Wage <[email protected]>
25-
* @author Roman Borschel <[email protected]>
26-
* @author Bernhard Schussek <[email protected]>
15+
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
2716
*/
2817
class Event
2918
{
30-
/**
31-
* @var bool Whether no further event listeners should be triggered
32-
*/
3319
private $propagationStopped = false;
3420

3521
/**
36-
* Returns whether further event listeners should be triggered.
37-
*
38-
* @see Event::stopPropagation()
39-
*
4022
* @return bool Whether propagation was already stopped for this event
23+
*
24+
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
4125
*/
4226
public function isPropagationStopped()
4327
{
4428
return $this->propagationStopped;
4529
}
4630

4731
/**
48-
* Stops the propagation of the event to further event listeners.
49-
*
50-
* If multiple event listeners are connected to the same event, no
51-
* further event listener will be triggered once any trigger calls
52-
* stopPropagation().
32+
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
5333
*/
5434
public function stopPropagation()
5535
{

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\EventDispatcher;
1313

1414
use Psr\EventDispatcher\StoppableEventInterface;
15+
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
1516

1617
/**
1718
* The EventDispatcherInterface is the central point of Symfony's event listener system.
@@ -237,7 +238,7 @@ protected function callListeners(iterable $listeners, string $eventName, $event)
237238
*/
238239
protected function doDispatch($listeners, $eventName, Event $event)
239240
{
240-
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
241+
$stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
241242

242243
foreach ($listeners as $listener) {
243244
if ($stoppable && $event->isPropagationStopped()) {

src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\EventDispatcher;
1313

1414
use Psr\EventDispatcher\StoppableEventInterface;
15+
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
1516
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1617

1718
/**
@@ -68,7 +69,7 @@ public function dispatch($event/*, string $eventName = null*/)
6869
}
6970

7071
$listeners = $this->getListeners($eventName);
71-
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
72+
$stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
7273

7374
foreach ($listeners as $listener) {
7475
if ($stoppable && $event->isPropagationStopped()) {

src/Symfony/Component/EventDispatcher/Tests/EventTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\EventDispatcher\Event;
1616

1717
/**
18-
* Test class for Event.
18+
* @group legacy
1919
*/
2020
class EventTest extends TestCase
2121
{

src/Symfony/Contracts/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ CHANGELOG
55
-----
66

77
* added `HttpClient` namespace with contracts for implementing flexible HTTP clients
8-
* added `EventDispatcher\EventDispatcherInterface`
9-
* added `ServiceProviderInterface`
8+
* added `EventDispatcherInterface` and `Event` in namespace `EventDispatcher`
9+
* added `ServiceProviderInterface` in namespace `Service`
1010

1111
1.0.0
1212
-----

0 commit comments

Comments
 (0)