Skip to content

Commit 5fd7b10

Browse files
[Contracts][EventDispatcher] add EventDispatcherInterface to symfony/contracts and use it where possible
1 parent 125a2c3 commit 5fd7b10

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

CHANGELOG.md

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

77
* added `HttpClient` namespace with contracts for implementing flexible HTTP clients
8+
* added `EventDispatcher\EventDispatcherInterface`
89

910
1.0.0
1011
-----
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Contracts\EventDispatcher;
13+
14+
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
15+
16+
if (interface_exists(PsrEventDispatcherInterface::class)) {
17+
/**
18+
* Allows providing hooks on domain-specific lifecycles by dispatching events.
19+
*/
20+
interface EventDispatcherInterface extends PsrEventDispatcherInterface
21+
{
22+
/**
23+
* Dispatches an event to all registered listeners.
24+
*
25+
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
26+
* signature of the method. Implementations that are not bound by this BC contraint
27+
* MUST declare it explicitly, as allowed by PHP.
28+
*
29+
* @param object $event The event to pass to the event handlers/listeners
30+
* @param string|null $eventName The name of the event to dispatch. If not supplied,
31+
* the class of $event should be used instead.
32+
*
33+
* @return object The passed $event MUST be returned
34+
*/
35+
public function dispatch($event/*, string $eventName = null*/);
36+
}
37+
} else {
38+
/**
39+
* Allows providing hooks on domain-specific lifecycles by dispatching events.
40+
*/
41+
interface EventDispatcherInterface
42+
{
43+
/**
44+
* Dispatches an event to all registered listeners.
45+
*
46+
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
47+
* signature of the method. Implementations that are not bound by this BC contraint
48+
* MUST declare it explicitly, as allowed by PHP.
49+
*
50+
* @param object $event The event to pass to the event handlers/listeners
51+
* @param string|null $eventName The name of the event to dispatch. If not supplied,
52+
* the class of $event should be used instead.
53+
*
54+
* @return object The passed $event MUST be returned
55+
*/
56+
public function dispatch($event/*, string $eventName = null*/);
57+
}
58+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"psr/cache": "When using the Cache contracts",
2828
"psr/container": "When using the Service contracts",
2929
"symfony/cache-contracts-implementation": "",
30+
"symfony/event-dispatcher-implementation": "",
3031
"symfony/http-client-contracts-implementation": "",
3132
"symfony/service-contracts-implementation": "",
3233
"symfony/translation-contracts-implementation": ""

0 commit comments

Comments
 (0)