10000 added two interfaces: EventInterface and EventDispatcherInterface · alexfilatov/symfony@0e66e38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e66e38

Browse files
committed
added two interfaces: EventInterface and EventDispatcherInterface
1 parent b325487 commit 0e66e38

31 files changed

+347
-168
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ParamConverterListener.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1818
use Symfony\Component\DependencyInjection\ContainerInterface;
19-
use Symfony\Component\EventDispatcher\EventDispatcher;
20-
use Symfony\Component\EventDispatcher\Event;
19+
use Symfony\Component\EventDispatcher\EventInterface;
2120

2221
/**
2322
* Converts \ReflectionParameters for Controller actions into Objects if the \ReflectionParameter have a class
@@ -44,14 +43,14 @@ public function __construct(ConverterManager $manager)
4443
}
4544

4645
/**
47-
* @param Event $event
48-
* @param mixed $controller
46+
* @param EventInterface $event
47+
* @param mixed $controller
4948
*
5049
* @return mixed
5150
*
5251
* @throws NotFoundHttpException
5352
*/
54-
public function filterController(Event $event, $controller)
53+
public function filterController(EventInterface $event, $controller)
5554
{
5655
if (!is_array($controller)) {
5756
return $controller;

src/Symfony/Bundle/FrameworkBundle/Debug/EventDispatcher.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Debug;
1313

1414
use Symfony\Bundle\FrameworkBundle\EventDispatcher as BaseEventDispatcher;
15-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16-
use Symfony\Component\EventDispatcher\Event;
15+
use Symfony\Component\EventDispatcher\EventInterface;
1716
use Symfony\Component\HttpKernel\Log\LoggerInterface;
1817
use Symfony\Component\HttpKernel\Debug\EventDispatcherTraceableInterface;
1918
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -45,7 +44,7 @@ public function __construct(ContainerInterface $container, LoggerInterface $logg
4544
/**
4645
* {@inheritDoc}
4746
*/
48-
public function notify(Event $event)
47+
public function notify(EventInterface $event)
4948
{
5049
foreach ($this->getListeners($event->getName()) as $listener) {
5150
if (is_array($listener) && is_string($listener[0])) {
@@ -63,7 +62,7 @@ public function notify(Event $event)
6362
/**
6463
* {@inheritDoc}
6564
*/
66-
public function notifyUntil(Event $event)
65+
public function notifyUntil(EventInterface $event)
6766
{
6867
foreach ($this->getListeners($event->getName()) as $i => $listener) {
6968
if (is_array($listener) && is_string($listener[0])) {
@@ -93,7 +92,7 @@ public function notifyUntil(Event $event)
9392
/**
9493
* {@inheritDoc}
9594
*/
96-
public function filter(Event $event, $value)
95+
public function filter(EventInterface $event, $value)
9796
{
9897
foreach ($this->getListeners($event->getName()) as $listener) {
9998
if (is_array($listener) && is_string($listener[0])) {
@@ -160,7 +159,7 @@ protected function listenerToString($listener)
160159
}
161160
}
162161

163-
protected function addCall(Event $event, $listener, $type)
162+
protected function addCall(EventInterface $event, $listener, $type)
164163
{
165164
$listener = $this->listenerToString($listener);
166165

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ protected function doConfigLoad(array $config, ContainerBuilder $container)
181181
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver',
182182
'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
183183

184+
'Symfony\\Component\\EventDispatcher\\EventInterface',
184185
'Symfony\\Component\\EventDispatcher\\Event',
186+
'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface',
185187
'Symfony\\Component\\EventDispatcher\\EventDispatcher',
186188
'Symfony\\Bundle\\FrameworkBundle\\EventDispatcher',
187189

src/Symfony/Bundle/FrameworkBundle/EventDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\EventDispatcher\EventDispatcher as BaseEventDispatcher;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
16-
use Symfony\Component\EventDispatcher\Event;
16+
use Symfony\Component\EventDispatcher\EventInterface;
1717

1818
/**
1919
* This EventDispatcher automatically gets the kernel listeners injected
@@ -42,7 +42,7 @@ public function registerKernelListeners(array $listeners)
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function notify(Event $event)
45+
public function notify(EventInterface $event)
4646
{
4747
foreach ($this->getListeners($event->getName()) as $listener) {
4848
if (is_array($listener) && is_string($listener[0])) {
@@ -57,7 +57,7 @@ public function notify(Event $event)
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function notifyUntil(Event $event)
60+
public function notifyUntil(EventInterface $event)
6161
{
6262
foreach ($this->getListeners($event->getName()) as $listener) {
6363
if (is_array($listener) && is_string($listener[0])) {
@@ -75,7 +75,7 @@ public function notifyUntil(Event $event)
7575
/**
7676
* {@inheritdoc}
7777
*/
78-
public function filter(Event $event, $value)
78+
public function filter(EventInterface $event, $value)
7979
{
8080
foreach ($this->getListeners($event->getName()) as $listener) {
8181
if (is_array($listener) && is_string($listener[0])) {

src/Symfony/Bundle/FrameworkBundle/HttpKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
88
use Symfony\Component\DependencyInjection\ContainerInterface;
99
use Symfony\Component\HttpKernel\HttpKernel as BaseHttpKernel;
10-
use Symfony\Component\EventDispatcher\EventDispatcher as BaseEventDispatcher;
10+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1111

1212
/**
1313
* This HttpKernel is used to manage scope changes of the DI container.
@@ -25,7 +25,7 @@ public function __construct(ContainerInterface $container, ControllerResolverInt
2525
$this->resolver = $controllerResolver;
2626
}
2727

28-
public function setEventDispatcher(BaseEventDispatcher $dispatcher)
28+
public function setEventDispatcher(EventDispatcherInterface $dispatcher)
2929
{
3030
$this->dispatcher = $dispatcher;
3131
}

src/Symfony/Bundle/FrameworkBundle/RequestListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\HttpKernel\Log\LoggerInterface;
1515
use Symfony\Component\HttpKernel\HttpKernelInterface;
1616
use Symfony\Component\HttpFoundation\Request;
17-
use Symfony\Component\EventDispatcher\Event;
17+
use Symfony\Component\EventDispatcher\EventInterface;
1818
use Symfony\Component\Routing\RouterInterface;
1919
use Symfony\Component\DependencyInjection\ContainerInterface;
2020

@@ -38,7 +38,7 @@ public function __construct(ContainerInterface $container, RouterInterface $rout
3838
$this->logger = $logger;
3939
}
4040

41-
public function handle(Event $event)
41+
public function handle(EventInterface $event)
4242
{
4343
$request = $event->get('request');
4444
$master = HttpKernelInterface::MASTER_REQUEST === $event->get('request_type');

src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Symfony\Bundle\WebProfilerBundle;
1313

14-
use Symfony\Component\EventDispatcher\EventDispatcher;
15-
use Symfony\Component\EventDispatcher\Event;
14+
use Symfony\Component\EventDispatcher\EventInterface;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\HttpFoundation\Response;
1817
use Symfony\Bundle\FrameworkBundle\HttpKernel;
@@ -36,7 +35,7 @@ public function __construct(HttpKernel $kernel, $interceptRedirects = false)
3635
$this->interceptRedirects = $interceptRedirects;
3736
}
3837

39-
public function handle(Event $event, Response $response)
38+
public function handle(EventInterface $event, Response $response)
4039
{
4140
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
4241
return $response;

src/Symfony/Component/EventDispatcher/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
1818
*/
19-
class Event
19+
class Event implements EventInterface
2020
{
2121
protected $value = null;
2222
protected $processed = false;

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
/**
1515
* EventDispatcher implements a dispatcher object.
1616
*
17-
* @see http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework
18-
*
1917
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2018
*/
21-
class EventDispatcher
19+
class EventDispatcher implements EventDispatcherInterface
2220
{
2321
protected $listeners = array();
2422

@@ -46,8 +44,8 @@ public function connect($name, $listener, $priority = 0)
4644
/**
4745
* Disconnects one, or all listeners for the given event name.
4846
*
49-
* @param string $name An event name
50-
* @param mixed|null $listener the listener to remove, or null to remove all
47+
* @param string $name An event name
48+
* @param mixed|null $listener The listener to remove, or null to remove all
5149
*
5250
* @return void
5351
*/
@@ -74,11 +72,11 @@ public function disconnect($name, $listener = null)
7472
/**
7573
* Notifies all listeners of a given event.
7674
*
77-
* @param Event $event An Event instance
75+
* @param EventInterface $event An EventInterface instance
7876
*
79-
* @return Event The Event instance
77+
* @return EventInterface The EventInterface instance
8078
*/
81-
public function notify(Event $event)
79+
public function notify(EventInterface $event)
8280
{
8381
foreach ($this->getListeners($event->getName()) as $listener) {
8482
call_user_func($listener, $event);
@@ -90,11 +88,11 @@ public function notify(Event $event)
9088
/**
9189
* Notifies all listeners of a given event until one returns a non null value.
9290
*
93-
* @param Event $event An Event instance
91+
* @param EventInterface $event An EventInterface instance
9492
*
95-
* @return Event The Event instance
93+
* @return EventInterface The EventInterface instance
9694
*/
97-
public function notifyUntil(Event $event)
95+
public function notifyUntil(EventInterface $event)
9896
{
9997
foreach ($this->getListeners($event->getName()) as $listener) {
10098
if (call_user_func($listener, $event)) {
@@ -109,12 +107,12 @@ public function notifyUntil(Event $event)
109107
/**
110108
* Filters a value by calling all listeners of a given event.
111109
*
112-
* @param Event $event An Event instance
113-
* @param mixed $value The value to be filtered
110+
* @param EventInterface $event An EventInterface instance
111+
* @param mixed $value The value to be filtered
114112
*
115-
* @return Event The Event instance
113+
* @return EventInterface The EventInterface instance
116114
*/
117-
public function filter(Event $event, $value)
115+
public function filter(EventInterface $event, $value)
118116
{
119117
foreach ($this->getListeners($event->getName()) as $listener) {
120118
$value = call_user_func($listener, $event, $value);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien.potencier@symfony-project.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\Component\EventDispatcher;
13+
14+
/**
15+
* EventDispatcherInterface describes an event dispatcher class.
16+
*
17+
* @see http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework
18+
*
19+
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
20+
*/
21+
interface EventDispatcherInterface
22+
{
23+
/**
24+
* Connects a listener to a given event name.
25+
*
26+
* Listeners with a higher priority are executed first.
27+
*
28+
* @param string $name An event name
29+
* @param mixed $listener A PHP callable
30+
* @param integer $priority The priority (between -10 and 10 -- defaults to 0)
31+
*/
32+
function connect($name, $listener, $priority = 0);
33+
34+
/**
35+
* Disconnects one, or all listeners for the given event name.
36+
*
37+
* @param string $name An event name
38+
* @param mixed|null $listener The listener to remove, or null to remove all
39+
*
40+
* @return void
41+
*/
42+
function disconnect($name, $listener = null);
43+
44+
/**
45+
* Notifies all listeners of a given event.
46+
*
47+
* @param EventInterface $event An EventInterface instance
48+
*
49+
* @return EventInterface The EventInterface instance
50+
*/
51+
function notify(EventInterface $event);
52+
53+
/**
54+
* Notifies all listeners of a given event until one returns a non null value.
55+
*
56+
* @param EventInterface $event An EventInterface instance
57+
*
58+
* @return EventInterface The EventInterface instance
59+
*/
60+
function notifyUntil(EventInterface $event);
61+
62+
/**
63+
* Filters a value by calling all listeners of a given event.
64+
*
65+
* @param EventInterface $event An EventInterface instance
66+
* @param mixed $value The value to be filtered
67+
*
68+
* @return EventInterface The EventInterface instance
69+
*/
70+
function filter(EventInterface $event, $value);
71+
72+
/**
73+
* Returns true if the given event name has some listeners.
74+
*
75+
* @param string $name The event name
76+
*
77+
* @return Boolean true if some listeners are connected, false otherwise
78+
*/
79+
function hasListeners($name);
80+
81+
/**
82+
* Returns all listeners associated with a given event name.
83+
*
84+
* @param string $name The event name
85+
*
86+
* @return array An array of listeners
87+
*/
88+
function getListeners($name);
89+
}

0 commit comments

Comments
 (0)
0