composer update
This commit is contained in:
6
vendor/symfony/event-dispatcher/CHANGELOG.md
vendored
6
vendor/symfony/event-dispatcher/CHANGELOG.md
vendored
@@ -1,6 +1,12 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated
|
||||
* deprecated the `Event` class, use `Symfony\Contracts\EventDispatcher\Event` instead
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
|
||||
@@ -11,11 +11,17 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\BrowserKit\Request;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventProxy;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
/**
|
||||
* Collects some data about event listeners.
|
||||
@@ -33,14 +39,17 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
private $dispatcher;
|
||||
private $wrappedListeners;
|
||||
private $orphanedEvents;
|
||||
private $requestStack;
|
||||
private $currentRequestHash = '';
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->logger = $logger;
|
||||
$this->wrappedListeners = [];
|
||||
$this->orphanedEvents = [];
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,37 +130,52 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($event/*, string $eventName = null*/)
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
$this->callStack = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
if (null === $event) {
|
||||
$event = new Event();
|
||||
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
|
||||
$eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;
|
||||
|
||||
if (\is_object($event)) {
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
} else {
|
||||
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
|
||||
$swap = $event;
|
||||
$event = $eventName ?? new Event();
|
||||
$eventName = $swap;
|
||||
|
||||
if (!$event instanceof Event) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->logger && $event->isPropagationStopped()) {
|
||||
if (null !== $this->logger && ($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
|
||||
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
|
||||
}
|
||||
|
||||
$this->preProcess($eventName);
|
||||
try {
|
||||
$this->preDispatch($eventName, $event);
|
||||
$this->beforeDispatch($eventName, $event);
|
||||
try {
|
||||
$e = $this->stopwatch->start($eventName, 'section');
|
||||
try {
|
||||
$this->dispatcher->dispatch($eventName, $event);
|
||||
$this->dispatcher->dispatch($event, $eventName);
|
||||
} finally {
|
||||
if ($e->isStarted()) {
|
||||
$e->stop();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
$this->postDispatch($eventName, $event);
|
||||
$this->afterDispatch($eventName, $event);
|
||||
}
|
||||
} finally {
|
||||
$this->currentRequestHash = $currentRequestHash;
|
||||
$this->postProcess($eventName);
|
||||
}
|
||||
|
||||
@@ -160,18 +184,22 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*/
|
||||
public function getCalledListeners()
|
||||
public function getCalledListeners(/* Request $request = null */)
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$hash = 1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) ? spl_object_hash($request) : null;
|
||||
$called = [];
|
||||
foreach ($this->callStack as $listener) {
|
||||
list($eventName) = $this->callStack->getInfo();
|
||||
|
||||
$called[] = $listener->getInfo($eventName);
|
||||
list($eventName, $requestHash) = $this->callStack->getInfo();
|
||||
if (null === $hash || $hash === $requestHash) {
|
||||
$called[] = $listener->getInfo($eventName);
|
||||
}
|
||||
}
|
||||
|
||||
return $called;
|
||||
@@ -179,8 +207,10 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*/
|
||||
public function getNotCalledListeners()
|
||||
public function getNotCalledListeners(/* Request $request = null */)
|
||||
{
|
||||
try {
|
||||
$allListeners = $this->getListeners();
|
||||
@@ -193,13 +223,15 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
$hash = 1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) ? spl_object_hash($request) : null;
|
||||
$notCalled = [];
|
||||
foreach ($allListeners as $eventName => $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
$called = false;
|
||||
if (null !== $this->callStack) {
|
||||
foreach ($this->callStack as $calledListener) {
|
||||
if ($calledListener->getWrappedListener() === $listener) {
|
||||
list(, $requestHash) = $this->callStack->getInfo();
|
||||
if ((null === $hash || $hash === $requestHash) && $calledListener->getWrappedListener() === $listener) {
|
||||
$called = true;
|
||||
|
||||
break;
|
||||
@@ -221,15 +253,27 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
return $notCalled;
|
||||
}
|
||||
|
||||
public function getOrphanedEvents(): array
|
||||
/**
|
||||
* @param Request|null $request The request to get orphaned events for
|
||||
*/
|
||||
public function getOrphanedEvents(/* Request $request = null */): array
|
||||
{
|
||||
return $this->orphanedEvents;
|
||||
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
|
||||
return $this->orphanedEvents[spl_object_hash($request)] ?? [];
|
||||
}
|
||||
|
||||
if (!$this->orphanedEvents) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_merge(...array_values($this->orphanedEvents));
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->callStack = null;
|
||||
$this->orphanedEvents = [];
|
||||
$this->currentRequestHash = '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,18 +292,32 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* Called before dispatching the event.
|
||||
*
|
||||
* @param string $eventName The event name
|
||||
* @param Event $event The event
|
||||
* @param object $event
|
||||
*/
|
||||
protected function beforeDispatch(string $eventName, $event)
|
||||
{
|
||||
$this->preDispatch($eventName, $event instanceof Event ? $event : new LegacyEventProxy($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after dispatching the event.
|
||||
*
|
||||
* @param object $event
|
||||
*/
|
||||
protected function afterDispatch(string $eventName, $event)
|
||||
{
|
||||
$this->postDispatch($eventName, $event instanceof Event ? $event : new LegacyEventProxy($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.3, will be removed in 5.0, use beforeDispatch instead
|
||||
*/
|
||||
protected function preDispatch($eventName, Event $event)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after dispatching the event.
|
||||
*
|
||||
* @param string $eventName The event name
|
||||
* @param Event $event The event
|
||||
* @deprecated since Symfony 4.3, will be removed in 5.0, use afterDispatch instead
|
||||
*/
|
||||
protected function postDispatch($eventName, Event $event)
|
||||
{
|
||||
@@ -268,7 +326,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
private function preProcess($eventName)
|
||||
{
|
||||
if (!$this->dispatcher->hasListeners($eventName)) {
|
||||
$this->orphanedEvents[] = $eventName;
|
||||
$this->orphanedEvents[$this->currentRequestHash][] = $eventName;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -279,7 +337,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
$this->wrappedListeners[$eventName][] = $wrappedListener;
|
||||
$this->dispatcher->removeListener($eventName, $listener);
|
||||
$this->dispatcher->addListener($eventName, $wrappedListener, $priority);
|
||||
$this->callStack->attach($wrappedListener, [$eventName]);
|
||||
$this->callStack->attach($wrappedListener, [$eventName, $this->currentRequestHash]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
@@ -24,14 +25,18 @@ interface TraceableEventDispatcherInterface extends EventDispatcherInterface, Re
|
||||
/**
|
||||
* Gets the called listeners.
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*
|
||||
* @return array An array of called listeners
|
||||
*/
|
||||
public function getCalledListeners();
|
||||
public function getCalledListeners(/* Request $request = null */);
|
||||
|
||||
/**
|
||||
* Gets the not called listeners.
|
||||
*
|
||||
* @param Request|null $request The request to get listeners for
|
||||
*
|
||||
* @return array An array of not called listeners
|
||||
*/
|
||||
public function getNotCalledListeners();
|
||||
public function getNotCalledListeners(/* Request $request = null */);
|
||||
}
|
||||
|
||||
@@ -11,17 +11,23 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Debug;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventProxy;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\VarDumper\Caster\ClassStub;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since Symfony 4.3: the "Event" type-hint on __invoke() will be replaced by "object" in 5.0
|
||||
*/
|
||||
class WrappedListener
|
||||
{
|
||||
private $listener;
|
||||
private $optimizedListener;
|
||||
private $name;
|
||||
private $called;
|
||||
private $stoppedPropagation;
|
||||
@@ -32,9 +38,10 @@ class WrappedListener
|
||||
private $priority;
|
||||
private static $hasClassStub;
|
||||
|
||||
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||
public function __construct($listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->listener = $listener;
|
||||
$this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null);
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->called = false;
|
||||
@@ -105,6 +112,10 @@ class WrappedListener
|
||||
|
||||
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
if ($event instanceof LegacyEventProxy) {
|
||||
$event = $event->getEvent();
|
||||
}
|
||||
|
||||
$dispatcher = $this->dispatcher ?: $dispatcher;
|
||||
|
||||
$this->called = true;
|
||||
@@ -112,13 +123,13 @@ class WrappedListener
|
||||
|
||||
$e = $this->stopwatch->start($this->name, 'event_listener');
|
||||
|
||||
($this->listener)($event, $eventName, $dispatcher);
|
||||
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
|
||||
|
||||
if ($e->isStarted()) {
|
||||
$e->stop();
|
||||
}
|
||||
|
||||
if ($event->isPropagationStopped()) {
|
||||
if (($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
|
||||
$this->stoppedPropagation = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,17 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
protected $dispatcherService;
|
||||
protected $listenerTag;
|
||||
protected $subscriberTag;
|
||||
protected $eventAliasesParameter;
|
||||
|
||||
private $hotPathEvents = [];
|
||||
private $hotPathTagName;
|
||||
|
||||
public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber')
|
||||
public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber', string $eventAliasesParameter = 'event_dispatcher.event_aliases')
|
||||
{
|
||||
$this->dispatcherService = $dispatcherService;
|
||||
$this->listenerTag = $listenerTag;
|
||||
$this->subscriberTag = $subscriberTag;
|
||||
$this->eventAliasesParameter = $eventAliasesParameter;
|
||||
}
|
||||
|
||||
public function setHotPathEvents(array $hotPathEvents, $tagName = 'container.hot_path')
|
||||
@@ -52,6 +54,12 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if ($container->hasParameter($this->eventAliasesParameter)) {
|
||||
$aliases = $container->getParameter($this->eventAliasesParameter);
|
||||
$container->getParameterBag()->remove($this->eventAliasesParameter);
|
||||
} else {
|
||||
$aliases = [];
|
||||
}
|
||||
$definition = $container->findDefinition($this->dispatcherService);
|
||||
|
||||
foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
|
||||
@@ -61,6 +69,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
if (!isset($event['event'])) {
|
||||
throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
|
||||
}
|
||||
$event['event'] = $aliases[$event['event']] ?? $event['event'];
|
||||
|
||||
if (!isset($event['method'])) {
|
||||
$event['method'] = 'on'.preg_replace_callback([
|
||||
@@ -98,6 +107,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
}
|
||||
$class = $r->name;
|
||||
|
||||
ExtractingEventDispatcher::$aliases = $aliases;
|
||||
ExtractingEventDispatcher::$subscriber = $class;
|
||||
$extractingDispatcher->addSubscriber($extractingDispatcher);
|
||||
foreach ($extractingDispatcher->listeners as $args) {
|
||||
@@ -109,6 +119,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
$extractingDispatcher->listeners = [];
|
||||
ExtractingEventDispatcher::$aliases = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +131,7 @@ class ExtractingEventDispatcher extends EventDispatcher implements EventSubscrib
|
||||
{
|
||||
public $listeners = [];
|
||||
|
||||
public static $aliases = [];
|
||||
public static $subscriber;
|
||||
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
@@ -129,8 +141,12 @@ class ExtractingEventDispatcher extends EventDispatcher implements EventSubscrib
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
$callback = [self::$subscriber, 'getSubscribedEvents'];
|
||||
$events = [];
|
||||
|
||||
return $callback();
|
||||
foreach ([self::$subscriber, 'getSubscribedEvents']() as $eventName => $params) {
|
||||
$events[self::$aliases[$eventName] ?? $eventName] = $params;
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
|
||||
28
vendor/symfony/event-dispatcher/Event.php
vendored
28
vendor/symfony/event-dispatcher/Event.php
vendored
@@ -12,32 +12,16 @@
|
||||
namespace Symfony\Component\EventDispatcher;
|
||||
|
||||
/**
|
||||
* Event is the base class for classes containing event data.
|
||||
*
|
||||
* This class contains no event data. It is used by events that do not pass
|
||||
* state information to an event handler when an event is raised.
|
||||
*
|
||||
* You can call the method stopPropagation() to abort the execution of
|
||||
* further listeners in your event listener.
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
/**
|
||||
* @var bool Whether no further event listeners should be triggered
|
||||
*/
|
||||
private $propagationStopped = false;
|
||||
|
||||
/**
|
||||
* Returns whether further event listeners should be triggered.
|
||||
*
|
||||
* @see Event::stopPropagation()
|
||||
*
|
||||
* @return bool Whether propagation was already stopped for this event
|
||||
*
|
||||
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
|
||||
*/
|
||||
public function isPropagationStopped()
|
||||
{
|
||||
@@ -45,11 +29,7 @@ class Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the propagation of the event to further event listeners.
|
||||
*
|
||||
* If multiple event listeners are connected to the same event, no
|
||||
* further event listener will be triggered once any trigger calls
|
||||
* stopPropagation().
|
||||
* @deprecated since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead
|
||||
*/
|
||||
public function stopPropagation()
|
||||
{
|
||||
|
||||
118
vendor/symfony/event-dispatcher/EventDispatcher.php
vendored
118
vendor/symfony/event-dispatcher/EventDispatcher.php
vendored
@@ -11,6 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
/**
|
||||
* The EventDispatcherInterface is the central point of Symfony's event listener system.
|
||||
*
|
||||
@@ -30,18 +34,45 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
{
|
||||
private $listeners = [];
|
||||
private $sorted = [];
|
||||
private $optimized;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (__CLASS__ === \get_class($this)) {
|
||||
$this->optimized = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($event/*, string $eventName = null*/)
|
||||
{
|
||||
if (null === $event) {
|
||||
$event = new Event();
|
||||
$eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;
|
||||
|
||||
if (\is_object($event)) {
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
} else {
|
||||
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
|
||||
$swap = $event;
|
||||
$event = $eventName ?? new Event();
|
||||
$eventName = $swap;
|
||||
|
||||
if (!$event instanceof Event) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
|
||||
}
|
||||
}
|
||||
|
||||
if ($listeners = $this->getListeners($eventName)) {
|
||||
$this->doDispatch($listeners, $eventName, $event);
|
||||
if (null !== $this->optimized && null !== $eventName) {
|
||||
$listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName));
|
||||
} else {
|
||||
$listeners = $this->getListeners($eventName);
|
||||
}
|
||||
|
||||
if ($listeners) {
|
||||
$this->callListeners($listeners, $eventName, $event);
|
||||
}
|
||||
|
||||
return $event;
|
||||
@@ -86,11 +117,10 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
$listener[0] = $listener[0]();
|
||||
}
|
||||
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
foreach ($listeners as $k => $v) {
|
||||
foreach ($this->listeners[$eventName] as $priority => &$listeners) {
|
||||
foreach ($listeners as &$v) {
|
||||
if ($v !== $listener && \is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
|
||||
$v[0] = $v[0]();
|
||||
$this->listeners[$eventName][$priority][$k] = $v;
|
||||
}
|
||||
if ($v === $listener) {
|
||||
return $priority;
|
||||
@@ -123,7 +153,7 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
{
|
||||
$this->listeners[$eventName][$priority][] = $listener;
|
||||
unset($this->sorted[$eventName]);
|
||||
unset($this->sorted[$eventName], $this->optimized[$eventName]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,21 +169,17 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
$listener[0] = $listener[0]();
|
||||
}
|
||||
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
foreach ($listeners as $k => $v) {
|
||||
foreach ($this->listeners[$eventName] as $priority => &$listeners) {
|
||||
foreach ($listeners as $k => &$v) {
|
||||
if ($v !== $listener && \is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
|
||||
$v[0] = $v[0]();
|
||||
}
|
||||
if ($v === $listener) {
|
||||
unset($listeners[$k], $this->sorted[$eventName]);
|
||||
} else {
|
||||
$listeners[$k] = $v;
|
||||
unset($listeners[$k], $this->sorted[$eventName], $this->optimized[$eventName]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($listeners) {
|
||||
$this->listeners[$eventName][$priority] = $listeners;
|
||||
} else {
|
||||
if (!$listeners) {
|
||||
unset($this->listeners[$eventName][$priority]);
|
||||
}
|
||||
}
|
||||
@@ -201,7 +227,29 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
*
|
||||
* @param callable[] $listeners The event listeners
|
||||
* @param string $eventName The name of the event to dispatch
|
||||
* @param Event $event The event object to pass to the event handlers/listeners
|
||||
* @param object $event The event object to pass to the event handlers/listeners
|
||||
*/
|
||||
protected function callListeners(iterable $listeners, string $eventName, $event)
|
||||
{
|
||||
if ($event instanceof Event) {
|
||||
$this->doDispatch($listeners, $eventName, $event);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$stoppable = $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
|
||||
|
||||
foreach ($listeners as $listener) {
|
||||
if ($stoppable && $event->isPropagationStopped()) {
|
||||
break;
|
||||
}
|
||||
// @deprecated: the ternary operator is part of a BC layer and should be removed in 5.0
|
||||
$listener($listener instanceof WrappedListener ? new LegacyEventProxy($event) : $event, $eventName, $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 4.3, use callListeners() instead
|
||||
*/
|
||||
protected function doDispatch($listeners, $eventName, Event $event)
|
||||
{
|
||||
@@ -215,22 +263,46 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
|
||||
/**
|
||||
* Sorts the internal list of listeners for the given event by priority.
|
||||
*
|
||||
* @param string $eventName The name of the event
|
||||
*/
|
||||
private function sortListeners($eventName)
|
||||
private function sortListeners(string $eventName)
|
||||
{
|
||||
krsort($this->listeners[$eventName]);
|
||||
$this->sorted[$eventName] = [];
|
||||
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
foreach ($this->listeners[$eventName] as &$listeners) {
|
||||
foreach ($listeners as $k => $listener) {
|
||||
if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
|
||||
$listener[0] = $listener[0]();
|
||||
$this->listeners[$eventName][$priority][$k] = $listener;
|
||||
}
|
||||
$this->sorted[$eventName][] = $listener;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimizes the internal list of listeners for the given event by priority.
|
||||
*/
|
||||
private function optimizeListeners(string $eventName): array
|
||||
{
|
||||
krsort($this->listeners[$eventName]);
|
||||
$this->optimized[$eventName] = [];
|
||||
|
||||
foreach ($this->listeners[$eventName] as &$listeners) {
|
||||
foreach ($listeners as &$listener) {
|
||||
$closure = &$this->optimized[$eventName][];
|
||||
if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
|
||||
$closure = static function (...$args) use (&$listener, &$closure) {
|
||||
if ($listener[0] instanceof \Closure) {
|
||||
$listener[0] = $listener[0]();
|
||||
}
|
||||
($closure = \Closure::fromCallable($listener))(...$args);
|
||||
};
|
||||
} else {
|
||||
$closure = $listener instanceof \Closure || $listener instanceof WrappedListener ? $listener : \Closure::fromCallable($listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->optimized[$eventName];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* The EventDispatcherInterface is the central point of Symfony's event listener system.
|
||||
* Listeners are registered on the manager and events are dispatched through the
|
||||
@@ -18,21 +20,8 @@ namespace Symfony\Component\EventDispatcher;
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface EventDispatcherInterface
|
||||
interface EventDispatcherInterface extends ContractsEventDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* Dispatches an event to all registered listeners.
|
||||
*
|
||||
* @param string $eventName The name of the event to dispatch. The name of
|
||||
* the event is the name of the method that is
|
||||
* invoked on listeners.
|
||||
* @param Event|null $event The event to pass to the event handlers/listeners
|
||||
* If not supplied, an empty Event instance is created
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null);
|
||||
|
||||
/**
|
||||
* Adds an event listener that listens on the specified events.
|
||||
*
|
||||
|
||||
@@ -22,15 +22,26 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($event/*, string $eventName = null*/)
|
||||
{
|
||||
return $this->dispatcher->dispatch($eventName, $event);
|
||||
$eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;
|
||||
|
||||
if (\is_scalar($event)) {
|
||||
// deprecated
|
||||
$swap = $event;
|
||||
$event = $eventName ?? new Event();
|
||||
$eventName = $swap;
|
||||
}
|
||||
|
||||
return $this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
147
vendor/symfony/event-dispatcher/LegacyEventDispatcherProxy.php
vendored
Normal file
147
vendor/symfony/event-dispatcher/LegacyEventDispatcherProxy.php
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* An helper class to provide BC/FC with the legacy signature of EventDispatcherInterface::dispatch().
|
||||
*
|
||||
* This class should be deprecated in Symfony 5.1
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
final class LegacyEventDispatcherProxy implements EventDispatcherInterface
|
||||
{
|
||||
private $dispatcher;
|
||||
|
||||
public static function decorate(?ContractsEventDispatcherInterface $dispatcher): ?ContractsEventDispatcherInterface
|
||||
{
|
||||
if (null === $dispatcher) {
|
||||
return null;
|
||||
}
|
||||
$r = new \ReflectionMethod($dispatcher, 'dispatch');
|
||||
$param2 = $r->getParameters()[1] ?? null;
|
||||
|
||||
if (!$param2 || !$param2->hasType() || $param2->getType()->isBuiltin()) {
|
||||
return $dispatcher;
|
||||
}
|
||||
|
||||
@trigger_error(sprintf('The signature of the "%s::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.', $r->class), E_USER_DEPRECATED);
|
||||
|
||||
$self = new self();
|
||||
$self->dispatcher = $dispatcher;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public function dispatch($event/*, string $eventName = null*/)
|
||||
{
|
||||
$eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;
|
||||
|
||||
if (\is_object($event)) {
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
} else {
|
||||
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', ContractsEventDispatcherInterface::class), E_USER_DEPRECATED);
|
||||
$swap = $event;
|
||||
$event = $eventName ?? new Event();
|
||||
$eventName = $swap;
|
||||
|
||||
if (!$event instanceof Event) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', ContractsEventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
|
||||
}
|
||||
}
|
||||
|
||||
$listeners = $this->getListeners($eventName);
|
||||
$stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
|
||||
|
||||
foreach ($listeners as $listener) {
|
||||
if ($stoppable && $event->isPropagationStopped()) {
|
||||
break;
|
||||
}
|
||||
$listener($event, $eventName, $this);
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
{
|
||||
return $this->dispatcher->addListener($eventName, $listener, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addSubscriber(EventSubscriberInterface $subscriber)
|
||||
{
|
||||
return $this->dispatcher->addSubscriber($subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeListener($eventName, $listener)
|
||||
{
|
||||
return $this->dispatcher->removeListener($eventName, $listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeSubscriber(EventSubscriberInterface $subscriber)
|
||||
{
|
||||
return $this->dispatcher->removeSubscriber($subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners($eventName = null)
|
||||
{
|
||||
return $this->dispatcher->getListeners($eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListenerPriority($eventName, $listener)
|
||||
{
|
||||
return $this->dispatcher->getListenerPriority($eventName, $listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners($eventName = null)
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxies all method calls to the original event dispatcher.
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
return $this->dispatcher->{$method}(...$arguments);
|
||||
}
|
||||
}
|
||||
62
vendor/symfony/event-dispatcher/LegacyEventProxy.php
vendored
Normal file
62
vendor/symfony/event-dispatcher/LegacyEventProxy.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
/**
|
||||
* @internal to be removed in 5.0.
|
||||
*/
|
||||
final class LegacyEventProxy extends Event
|
||||
{
|
||||
private $event;
|
||||
|
||||
/**
|
||||
* @param object $event
|
||||
*/
|
||||
public function __construct($event)
|
||||
{
|
||||
$this->event = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object $event
|
||||
*/
|
||||
public function getEvent()
|
||||
{
|
||||
return $this->event;
|
||||
}
|
||||
|
||||
public function isPropagationStopped()
|
||||
{
|
||||
if (!$this->event instanceof ContractsEvent && !$this->event instanceof StoppableEventInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->event->isPropagationStopped();
|
||||
}
|
||||
|
||||
public function stopPropagation()
|
||||
{
|
||||
if (!$this->event instanceof ContractsEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->event->stopPropagation();
|
||||
}
|
||||
|
||||
public function __call($name, $args)
|
||||
{
|
||||
return $this->event->{$name}(...$args);
|
||||
}
|
||||
}
|
||||
@@ -1,442 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
abstract class AbstractEventDispatcherTest extends TestCase
|
||||
{
|
||||
/* Some pseudo events */
|
||||
const preFoo = 'pre.foo';
|
||||
const postFoo = 'post.foo';
|
||||
const preBar = 'pre.bar';
|
||||
const postBar = 'post.bar';
|
||||
|
||||
/**
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
private $listener;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->dispatcher = $this->createEventDispatcher();
|
||||
$this->listener = new TestEventListener();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->dispatcher = null;
|
||||
$this->listener = null;
|
||||
}
|
||||
|
||||
abstract protected function createEventDispatcher();
|
||||
|
||||
public function testInitialState()
|
||||
{
|
||||
$this->assertEquals([], $this->dispatcher->getListeners());
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testAddListener()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
|
||||
$this->assertCount(1, $this->dispatcher->getListeners(self::postFoo));
|
||||
$this->assertCount(2, $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testGetListenersSortsByPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
$listener3 = new TestEventListener();
|
||||
$listener1->name = '1';
|
||||
$listener2->name = '2';
|
||||
$listener3->name = '3';
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']);
|
||||
|
||||
$expected = [
|
||||
[$listener2, 'preFoo'],
|
||||
[$listener3, 'preFoo'],
|
||||
[$listener1, 'preFoo'],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
|
||||
}
|
||||
|
||||
public function testGetAllListenersSortsByPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
$listener3 = new TestEventListener();
|
||||
$listener4 = new TestEventListener();
|
||||
$listener5 = new TestEventListener();
|
||||
$listener6 = new TestEventListener();
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||
$this->dispatcher->addListener('post.foo', $listener4, -10);
|
||||
$this->dispatcher->addListener('post.foo', $listener5);
|
||||
$this->dispatcher->addListener('post.foo', $listener6, 10);
|
||||
|
||||
$expected = [
|
||||
'pre.foo' => [$listener3, $listener2, $listener1],
|
||||
'post.foo' => [$listener6, $listener5, $listener4],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testGetListenerPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
|
||||
$this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
|
||||
$this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
|
||||
}
|
||||
|
||||
public function testDispatch()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||
$this->dispatcher->dispatch(self::preFoo);
|
||||
$this->assertTrue($this->listener->preFooInvoked);
|
||||
$this->assertFalse($this->listener->postFooInvoked);
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch('noevent'));
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(self::preFoo));
|
||||
$event = new Event();
|
||||
$return = $this->dispatcher->dispatch(self::preFoo, $event);
|
||||
$this->assertSame($event, $return);
|
||||
}
|
||||
|
||||
public function testDispatchForClosure()
|
||||
{
|
||||
$invoked = 0;
|
||||
$listener = function () use (&$invoked) {
|
||||
++$invoked;
|
||||
};
|
||||
$this->dispatcher->addListener('pre.foo', $listener);
|
||||
$this->dispatcher->addListener('post.foo', $listener);
|
||||
$this->dispatcher->dispatch(self::preFoo);
|
||||
$this->assertEquals(1, $invoked);
|
||||
}
|
||||
|
||||
public function testStopEventPropagation()
|
||||
{
|
||||
$otherListener = new TestEventListener();
|
||||
|
||||
// postFoo() stops the propagation, so only one listener should
|
||||
// be executed
|
||||
// Manually set priority to enforce $this->listener to be called first
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
|
||||
$this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
|
||||
$this->dispatcher->dispatch(self::postFoo);
|
||||
$this->assertTrue($this->listener->postFooInvoked);
|
||||
$this->assertFalse($otherListener->postFooInvoked);
|
||||
}
|
||||
|
||||
public function testDispatchByPriority()
|
||||
{
|
||||
$invoked = [];
|
||||
$listener1 = function () use (&$invoked) {
|
||||
$invoked[] = '1';
|
||||
};
|
||||
$listener2 = function () use (&$invoked) {
|
||||
$invoked[] = '2';
|
||||
};
|
||||
$listener3 = function () use (&$invoked) {
|
||||
$invoked[] = '3';
|
||||
};
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||
$this->dispatcher->dispatch(self::preFoo);
|
||||
$this->assertEquals(['3', '2', '1'], $invoked);
|
||||
}
|
||||
|
||||
public function testRemoveListener()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.bar', $this->listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preBar));
|
||||
$this->dispatcher->removeListener('pre.bar', $this->listener);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preBar));
|
||||
$this->dispatcher->removeListener('notExists', $this->listener);
|
||||
}
|
||||
|
||||
public function testAddSubscriber()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testAddSubscriberWithPriorities()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$eventSubscriber = new TestEventSubscriberWithPriorities();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$listeners = $this->dispatcher->getListeners('pre.foo');
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $listeners);
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Tests\TestEventSubscriberWithPriorities', $listeners[0][0]);
|
||||
}
|
||||
|
||||
public function testAddSubscriberWithMultipleListeners()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$listeners = $this->dispatcher->getListeners('pre.foo');
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $listeners);
|
||||
$this->assertEquals('preFoo2', $listeners[0][1]);
|
||||
}
|
||||
|
||||
public function testRemoveSubscriber()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testRemoveSubscriberWithPriorities()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithPriorities();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
}
|
||||
|
||||
public function testRemoveSubscriberWithMultipleListeners()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $this->dispatcher->getListeners(self::preFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
}
|
||||
|
||||
public function testEventReceivesTheDispatcherInstanceAsArgument()
|
||||
{
|
||||
$listener = new TestWithDispatcher();
|
||||
$this->dispatcher->addListener('test', [$listener, 'foo']);
|
||||
$this->assertNull($listener->name);
|
||||
$this->assertNull($listener->dispatcher);
|
||||
$this->dispatcher->dispatch('test');
|
||||
$this->assertEquals('test', $listener->name);
|
||||
$this->assertSame($this->dispatcher, $listener->dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://bugs.php.net/bug.php?id=62976
|
||||
*
|
||||
* This bug affects:
|
||||
* - The PHP 5.3 branch for versions < 5.3.18
|
||||
* - The PHP 5.4 branch for versions < 5.4.8
|
||||
* - The PHP 5.5 branch is not affected
|
||||
*/
|
||||
public function testWorkaroundForPhpBug62976()
|
||||
{
|
||||
$dispatcher = $this->createEventDispatcher();
|
||||
$dispatcher->addListener('bug.62976', new CallableClass());
|
||||
$dispatcher->removeListener('bug.62976', function () {});
|
||||
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
|
||||
}
|
||||
|
||||
public function testHasListenersWhenAddedCallbackListenerIsRemoved()
|
||||
{
|
||||
$listener = function () {};
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->dispatcher->removeListener('foo', $listener);
|
||||
$this->assertFalse($this->dispatcher->hasListeners());
|
||||
}
|
||||
|
||||
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
|
||||
{
|
||||
$listener = function () {};
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->dispatcher->removeListener('foo', $listener);
|
||||
$this->assertSame([], $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
|
||||
{
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertFalse($this->dispatcher->hasListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersIsLazy()
|
||||
{
|
||||
$called = 0;
|
||||
$listener = [function () use (&$called) { ++$called; }, 'onFoo'];
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertSame(0, $called);
|
||||
}
|
||||
|
||||
public function testDispatchLazyListener()
|
||||
{
|
||||
$called = 0;
|
||||
$factory = function () use (&$called) {
|
||||
++$called;
|
||||
|
||||
return new TestWithDispatcher();
|
||||
};
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertSame(0, $called);
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
$this->assertSame(1, $called);
|
||||
}
|
||||
|
||||
public function testRemoveFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
}
|
||||
|
||||
public function testPriorityFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', [$test, 'foo']));
|
||||
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo'], 5);
|
||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', [$factory, 'foo']));
|
||||
}
|
||||
|
||||
public function testGetLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||
$this->assertSame([[$test, 'foo']], $this->dispatcher->getListeners('foo'));
|
||||
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->dispatcher->addListener('bar', [$factory, 'foo'], 3);
|
||||
$this->assertSame(['bar' => [[$test, 'foo']]], $this->dispatcher->getListeners());
|
||||
}
|
||||
}
|
||||
|
||||
class CallableClass
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventListener
|
||||
{
|
||||
public $preFooInvoked = false;
|
||||
public $postFooInvoked = false;
|
||||
|
||||
/* Listener methods */
|
||||
|
||||
public function preFoo(Event $e)
|
||||
{
|
||||
$this->preFooInvoked = true;
|
||||
}
|
||||
|
||||
public function postFoo(Event $e)
|
||||
{
|
||||
$this->postFooInvoked = true;
|
||||
|
||||
$e->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
class TestWithDispatcher
|
||||
{
|
||||
public $name;
|
||||
public $dispatcher;
|
||||
|
||||
public function foo(Event $e, $name, $dispatcher)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return ['pre.foo' => 'preFoo', 'post.foo' => 'postFoo'];
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriberWithPriorities implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'pre.foo' => ['preFoo', 10],
|
||||
'post.foo' => ['postFoo'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return ['pre.foo' => [
|
||||
['preFoo1'],
|
||||
['preFoo2', 10],
|
||||
]];
|
||||
}
|
||||
}
|
||||
26
vendor/symfony/event-dispatcher/Tests/ChildEventDispatcherTest.php
vendored
Normal file
26
vendor/symfony/event-dispatcher/Tests/ChildEventDispatcherTest.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Tests;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
class ChildEventDispatcherTest extends EventDispatcherTest
|
||||
{
|
||||
protected function createEventDispatcher()
|
||||
{
|
||||
return new ChildEventDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
class ChildEventDispatcher extends EventDispatcher
|
||||
{
|
||||
}
|
||||
@@ -18,6 +18,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
class TraceableEventDispatcherTest extends TestCase
|
||||
{
|
||||
@@ -69,7 +70,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
|
||||
// Verify that priority is preserved when listener is removed and re-added
|
||||
// in preProcess() and postProcess().
|
||||
$tdispatcher->dispatch('foo', new Event());
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
$listeners = $dispatcher->getListeners('foo');
|
||||
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
|
||||
}
|
||||
@@ -84,7 +85,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
};
|
||||
|
||||
$tdispatcher->addListener('bar', $listener, 5);
|
||||
$tdispatcher->dispatch('bar');
|
||||
$tdispatcher->dispatch(new Event(), 'bar');
|
||||
$this->assertSame(5, $priorityWhileDispatching);
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$this->assertEquals([], $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$listeners = $tdispatcher->getCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
@@ -129,7 +130,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->addListener('foo', function () {}, 5);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
$tdispatcher->reset();
|
||||
|
||||
$listeners = $tdispatcher->getNotCalledListeners();
|
||||
@@ -139,13 +140,26 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners);
|
||||
}
|
||||
|
||||
public function testDispatchContractsEvent()
|
||||
{
|
||||
$expectedEvent = new ContractsEvent();
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->addListener('foo', function ($event) use ($expectedEvent) {
|
||||
$this->assertSame($event, $expectedEvent);
|
||||
}, 5);
|
||||
$tdispatcher->dispatch($expectedEvent, 'foo');
|
||||
|
||||
$listeners = $tdispatcher->getCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
}
|
||||
|
||||
public function testDispatchAfterReset()
|
||||
{
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->addListener('foo', function () {}, 5);
|
||||
|
||||
$tdispatcher->reset();
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$listeners = $tdispatcher->getCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
@@ -157,10 +171,10 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$dispatcher->addListener('foo', function (Event $event, $eventName, $dispatcher) use (&$tdispatcher) {
|
||||
$tdispatcher = $dispatcher;
|
||||
$dispatcher->dispatch('bar');
|
||||
$dispatcher->dispatch(new Event(), 'bar');
|
||||
});
|
||||
$dispatcher->addListener('bar', function (Event $event) {});
|
||||
$dispatcher->dispatch('foo');
|
||||
$dispatcher->dispatch(new Event(), 'foo');
|
||||
$this->assertSame($dispatcher, $tdispatcher);
|
||||
$this->assertCount(2, $dispatcher->getCalledListeners());
|
||||
}
|
||||
@@ -175,7 +189,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
public function testItReturnsOrphanedEventsAfterDispatch()
|
||||
{
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
$events = $tdispatcher->getOrphanedEvents();
|
||||
$this->assertCount(1, $events);
|
||||
$this->assertEquals(['foo'], $events);
|
||||
@@ -185,7 +199,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
{
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->addListener('foo', function () {});
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
$events = $tdispatcher->getOrphanedEvents();
|
||||
$this->assertEmpty($events);
|
||||
}
|
||||
@@ -202,7 +216,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']);
|
||||
$logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
}
|
||||
|
||||
public function testLoggerWithStoppedEvent()
|
||||
@@ -218,7 +232,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']);
|
||||
$logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
}
|
||||
|
||||
public function testDispatchCallListeners()
|
||||
@@ -230,7 +244,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10);
|
||||
$tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertSame(['foo2', 'foo1'], $called);
|
||||
}
|
||||
@@ -243,14 +257,14 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) {
|
||||
++$loop;
|
||||
if (2 == $loop) {
|
||||
$dispatcher->dispatch('foo');
|
||||
$dispatcher->dispatch(new Event(), 'foo');
|
||||
}
|
||||
});
|
||||
$dispatcher->addListener('foo', function () use (&$dispatchedEvents) {
|
||||
++$dispatchedEvents;
|
||||
});
|
||||
|
||||
$dispatcher->dispatch('foo');
|
||||
$dispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertSame(2, $dispatchedEvents);
|
||||
}
|
||||
@@ -260,14 +274,14 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$nestedCall = false;
|
||||
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$dispatcher->addListener('foo', function (Event $e) use ($dispatcher) {
|
||||
$dispatcher->dispatch('bar', $e);
|
||||
$dispatcher->dispatch(new Event(), 'bar', $e);
|
||||
});
|
||||
$dispatcher->addListener('bar', function (Event $e) use (&$nestedCall) {
|
||||
$nestedCall = true;
|
||||
});
|
||||
|
||||
$this->assertFalse($nestedCall);
|
||||
$dispatcher->dispatch('foo');
|
||||
$dispatcher->dispatch(new Event(), 'foo');
|
||||
$this->assertTrue($nestedCall);
|
||||
}
|
||||
|
||||
@@ -279,7 +293,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
};
|
||||
$eventDispatcher->addListener('foo', $listener1);
|
||||
$eventDispatcher->addListener('foo', function () {});
|
||||
$eventDispatcher->dispatch('foo');
|
||||
$eventDispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
|
||||
}
|
||||
@@ -287,7 +301,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
public function testClearOrphanedEvents()
|
||||
{
|
||||
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||
$tdispatcher->dispatch('foo');
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
$events = $tdispatcher->getOrphanedEvents();
|
||||
$this->assertCount(1, $events);
|
||||
$tdispatcher->reset();
|
||||
|
||||
@@ -21,7 +21,7 @@ class WrappedListenerTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideListenersToDescribe
|
||||
*/
|
||||
public function testListenerDescription(callable $listener, $expected)
|
||||
public function testListenerDescription($listener, $expected)
|
||||
{
|
||||
$wrappedListener = new WrappedListener($listener, null, $this->getMockBuilder(Stopwatch::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock());
|
||||
|
||||
@@ -34,6 +34,7 @@ class WrappedListenerTest extends TestCase
|
||||
[new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'],
|
||||
[[new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
|
||||
[['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'],
|
||||
[['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'invalidMethod'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::invalidMethod'],
|
||||
['var_dump', 'var_dump'],
|
||||
[function () {}, 'closure'],
|
||||
[\Closure::fromCallable([new FooListener(), 'listen']), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
|
||||
|
||||
@@ -11,12 +11,476 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
|
||||
|
||||
class EventDispatcherTest extends AbstractEventDispatcherTest
|
||||
class EventDispatcherTest extends TestCase
|
||||
{
|
||||
/* Some pseudo events */
|
||||
const preFoo = 'pre.foo';
|
||||
const postFoo = 'post.foo';
|
||||
const preBar = 'pre.bar';
|
||||
const postBar = 'post.bar';
|
||||
|
||||
/**
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
private $listener;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->dispatcher = $this->createEventDispatcher();
|
||||
$this->listener = new TestEventListener();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->dispatcher = null;
|
||||
$this->listener = null;
|
||||
}
|
||||
|
||||
protected function createEventDispatcher()
|
||||
{
|
||||
return new EventDispatcher();
|
||||
}
|
||||
|
||||
public function testInitialState()
|
||||
{
|
||||
$this->assertEquals([], $this->dispatcher->getListeners());
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testAddListener()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
|
||||
$this->assertCount(1, $this->dispatcher->getListeners(self::postFoo));
|
||||
$this->assertCount(2, $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testGetListenersSortsByPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
$listener3 = new TestEventListener();
|
||||
$listener1->name = '1';
|
||||
$listener2->name = '2';
|
||||
$listener3->name = '3';
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']);
|
||||
|
||||
$expected = [
|
||||
[$listener2, 'preFoo'],
|
||||
[$listener3, 'preFoo'],
|
||||
[$listener1, 'preFoo'],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
|
||||
}
|
||||
|
||||
public function testGetAllListenersSortsByPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
$listener3 = new TestEventListener();
|
||||
$listener4 = new TestEventListener();
|
||||
$listener5 = new TestEventListener();
|
||||
$listener6 = new TestEventListener();
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||
$this->dispatcher->addListener('post.foo', $listener4, -10);
|
||||
$this->dispatcher->addListener('post.foo', $listener5);
|
||||
$this->dispatcher->addListener('post.foo', $listener6, 10);
|
||||
|
||||
$expected = [
|
||||
'pre.foo' => [$listener3, $listener2, $listener1],
|
||||
'post.foo' => [$listener6, $listener5, $listener4],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testGetListenerPriority()
|
||||
{
|
||||
$listener1 = new TestEventListener();
|
||||
$listener2 = new TestEventListener();
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
|
||||
$this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
|
||||
$this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
|
||||
$this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
|
||||
}
|
||||
|
||||
public function testDispatch()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||
$this->dispatcher->dispatch(new Event(), self::preFoo);
|
||||
$this->assertTrue($this->listener->preFooInvoked);
|
||||
$this->assertFalse($this->listener->postFooInvoked);
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), 'noevent'));
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), self::preFoo));
|
||||
$event = new Event();
|
||||
$return = $this->dispatcher->dispatch($event, self::preFoo);
|
||||
$this->assertSame($event, $return);
|
||||
}
|
||||
|
||||
public function testDispatchContractsEvent()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||
$this->dispatcher->dispatch(new ContractsEvent(), self::preFoo);
|
||||
$this->assertTrue($this->listener->preFooInvoked);
|
||||
$this->assertFalse($this->listener->postFooInvoked);
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), 'noevent'));
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), self::preFoo));
|
||||
$event = new Event();
|
||||
$return = $this->dispatcher->dispatch($event, self::preFoo);
|
||||
$this->assertSame($event, $return);
|
||||
}
|
||||
|
||||
public function testDispatchForClosure()
|
||||
{
|
||||
$invoked = 0;
|
||||
$listener = function () use (&$invoked) {
|
||||
++$invoked;
|
||||
};
|
||||
$this->dispatcher->addListener('pre.foo', $listener);
|
||||
$this->dispatcher->addListener('post.foo', $listener);
|
||||
$this->dispatcher->dispatch(new Event(), self::preFoo);
|
||||
$this->assertEquals(1, $invoked);
|
||||
}
|
||||
|
||||
public function testStopEventPropagation()
|
||||
{
|
||||
$otherListener = new TestEventListener();
|
||||
|
||||
// postFoo() stops the propagation, so only one listener should
|
||||
// be executed
|
||||
// Manually set priority to enforce $this->listener to be called first
|
||||
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
|
||||
$this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
|
||||
$this->dispatcher->dispatch(new Event(), self::postFoo);
|
||||
$this->assertTrue($this->listener->postFooInvoked);
|
||||
$this->assertFalse($otherListener->postFooInvoked);
|
||||
}
|
||||
|
||||
public function testDispatchByPriority()
|
||||
{
|
||||
$invoked = [];
|
||||
$listener1 = function () use (&$invoked) {
|
||||
$invoked[] = '1';
|
||||
};
|
||||
$listener2 = function () use (&$invoked) {
|
||||
$invoked[] = '2';
|
||||
};
|
||||
$listener3 = function () use (&$invoked) {
|
||||
$invoked[] = '3';
|
||||
};
|
||||
$this->dispatcher->addListener('pre.foo', $listener1, -10);
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||
$this->dispatcher->dispatch(new Event(), self::preFoo);
|
||||
$this->assertEquals(['3', '2', '1'], $invoked);
|
||||
}
|
||||
|
||||
public function testRemoveListener()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.bar', $this->listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preBar));
|
||||
$this->dispatcher->removeListener('pre.bar', $this->listener);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preBar));
|
||||
$this->dispatcher->removeListener('notExists', $this->listener);
|
||||
}
|
||||
|
||||
public function testAddSubscriber()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testAddSubscriberWithPriorities()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$eventSubscriber = new TestEventSubscriberWithPriorities();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$listeners = $this->dispatcher->getListeners('pre.foo');
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $listeners);
|
||||
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Tests\TestEventSubscriberWithPriorities', $listeners[0][0]);
|
||||
}
|
||||
|
||||
public function testAddSubscriberWithMultipleListeners()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
|
||||
$listeners = $this->dispatcher->getListeners('pre.foo');
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $listeners);
|
||||
$this->assertEquals('preFoo2', $listeners[0][1]);
|
||||
}
|
||||
|
||||
public function testRemoveSubscriber()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriber();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
||||
}
|
||||
|
||||
public function testRemoveSubscriberWithPriorities()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithPriorities();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
}
|
||||
|
||||
public function testRemoveSubscriberWithMultipleListeners()
|
||||
{
|
||||
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
|
||||
$this->dispatcher->addSubscriber($eventSubscriber);
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertCount(2, $this->dispatcher->getListeners(self::preFoo));
|
||||
$this->dispatcher->removeSubscriber($eventSubscriber);
|
||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||
}
|
||||
|
||||
public function testEventReceivesTheDispatcherInstanceAsArgument()
|
||||
{
|
||||
$listener = new TestWithDispatcher();
|
||||
$this->dispatcher->addListener('test', [$listener, 'foo']);
|
||||
$this->assertNull($listener->name);
|
||||
$this->assertNull($listener->dispatcher);
|
||||
$this->dispatcher->dispatch(new Event(), 'test');
|
||||
$this->assertEquals('test', $listener->name);
|
||||
$this->assertSame($this->dispatcher, $listener->dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://bugs.php.net/bug.php?id=62976
|
||||
*
|
||||
* This bug affects:
|
||||
* - The PHP 5.3 branch for versions < 5.3.18
|
||||
* - The PHP 5.4 branch for versions < 5.4.8
|
||||
* - The PHP 5.5 branch is not affected
|
||||
*/
|
||||
public function testWorkaroundForPhpBug62976()
|
||||
{
|
||||
$dispatcher = $this->createEventDispatcher();
|
||||
$dispatcher->addListener('bug.62976', new CallableClass());
|
||||
$dispatcher->removeListener('bug.62976', function () {});
|
||||
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
|
||||
}
|
||||
|
||||
public function testHasListenersWhenAddedCallbackListenerIsRemoved()
|
||||
{
|
||||
$listener = function () {};
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->dispatcher->removeListener('foo', $listener);
|
||||
$this->assertFalse($this->dispatcher->hasListeners());
|
||||
}
|
||||
|
||||
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
|
||||
{
|
||||
$listener = function () {};
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->dispatcher->removeListener('foo', $listener);
|
||||
$this->assertSame([], $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
|
||||
{
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertFalse($this->dispatcher->hasListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersIsLazy()
|
||||
{
|
||||
$called = 0;
|
||||
$listener = [function () use (&$called) { ++$called; }, 'onFoo'];
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertSame(0, $called);
|
||||
}
|
||||
|
||||
public function testDispatchLazyListener()
|
||||
{
|
||||
$called = 0;
|
||||
$factory = function () use (&$called) {
|
||||
++$called;
|
||||
|
||||
return new TestWithDispatcher();
|
||||
};
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertSame(0, $called);
|
||||
$this->dispatcher->dispatch(new Event(), 'foo');
|
||||
$this->dispatcher->dispatch(new Event(), 'foo');
|
||||
$this->assertSame(1, $called);
|
||||
}
|
||||
|
||||
public function testRemoveFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
}
|
||||
|
||||
public function testPriorityFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', [$test, 'foo']));
|
||||
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo'], 5);
|
||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', [$factory, 'foo']));
|
||||
}
|
||||
|
||||
public function testGetLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||
$this->assertSame([[$test, 'foo']], $this->dispatcher->getListeners('foo'));
|
||||
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->dispatcher->addListener('bar', [$factory, 'foo'], 3);
|
||||
$this->assertSame(['bar' => [[$test, 'foo']]], $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testMutatingWhilePropagationIsStopped()
|
||||
{
|
||||
$testLoaded = false;
|
||||
$test = new TestEventListener();
|
||||
$this->dispatcher->addListener('foo', [$test, 'postFoo']);
|
||||
$this->dispatcher->addListener('foo', [function () use ($test, &$testLoaded) {
|
||||
$testLoaded = true;
|
||||
|
||||
return $test;
|
||||
}, 'preFoo']);
|
||||
|
||||
$this->dispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertTrue($test->postFooInvoked);
|
||||
$this->assertFalse($test->preFooInvoked);
|
||||
|
||||
$this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo']));
|
||||
|
||||
$test->preFoo(new Event());
|
||||
$this->dispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertTrue($testLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
class CallableClass
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventListener
|
||||
{
|
||||
public $preFooInvoked = false;
|
||||
public $postFooInvoked = false;
|
||||
|
||||
/* Listener methods */
|
||||
|
||||
public function preFoo($e)
|
||||
{
|
||||
$this->preFooInvoked = true;
|
||||
}
|
||||
|
||||
public function postFoo($e)
|
||||
{
|
||||
$this->postFooInvoked = true;
|
||||
|
||||
if (!$this->preFooInvoked) {
|
||||
$e->stopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestWithDispatcher
|
||||
{
|
||||
public $name;
|
||||
public $dispatcher;
|
||||
|
||||
public function foo($e, $name, $dispatcher)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return ['pre.foo' => 'preFoo', 'post.foo' => 'postFoo'];
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriberWithPriorities implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'pre.foo' => ['preFoo', 10],
|
||||
'post.foo' => ['postFoo'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return ['pre.foo' => [
|
||||
['preFoo1'],
|
||||
['preFoo2', 10],
|
||||
]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Test class for Event.
|
||||
* @group legacy
|
||||
*/
|
||||
class EventTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -92,7 +92,7 @@ class GenericEventTest extends TestCase
|
||||
$this->assertEquals('Event', $this->event['name']);
|
||||
|
||||
// test getting invalid arg
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->assertFalse($this->event['nameNotExist']);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ class ImmutableEventDispatcherTest extends TestCase
|
||||
|
||||
$this->innerDispatcher->expects($this->once())
|
||||
->method('dispatch')
|
||||
->with('event', $event)
|
||||
->with($event, 'event')
|
||||
->will($this->returnValue('result'));
|
||||
|
||||
$this->assertSame('result', $this->dispatcher->dispatch('event', $event));
|
||||
$this->assertSame('result', $this->dispatcher->dispatch($event, 'event'));
|
||||
}
|
||||
|
||||
public function testGetListenersDelegates()
|
||||
|
||||
35
vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherTest.php
vendored
Normal file
35
vendor/symfony/event-dispatcher/Tests/LegacyEventDispatcherTest.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Tests;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LegacyEventDispatcherTest extends EventDispatcherTest
|
||||
{
|
||||
protected function createEventDispatcher()
|
||||
{
|
||||
return LegacyEventDispatcherProxy::decorate(new TestLegacyEventDispatcher());
|
||||
}
|
||||
}
|
||||
|
||||
class TestLegacyEventDispatcher extends EventDispatcher
|
||||
{
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
{
|
||||
return parent::dispatch($event, $eventName);
|
||||
}
|
||||
}
|
||||
10
vendor/symfony/event-dispatcher/composer.json
vendored
10
vendor/symfony/event-dispatcher/composer.json
vendored
@@ -17,18 +17,24 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/contracts": "^1.0"
|
||||
"symfony/event-dispatcher-contracts": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/expression-language": "~3.4|~4.0",
|
||||
"symfony/config": "~3.4|~4.0",
|
||||
"symfony/http-foundation": "^3.4|^4.0",
|
||||
"symfony/service-contracts": "^1.1",
|
||||
"symfony/stopwatch": "~3.4|~4.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/dependency-injection": "<3.4"
|
||||
},
|
||||
"provide": {
|
||||
"psr/event-dispatcher-implementation": "1.0",
|
||||
"symfony/event-dispatcher-implementation": "1.1"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/dependency-injection": "",
|
||||
"symfony/http-kernel": ""
|
||||
@@ -42,7 +48,7 @@
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
"dev-master": "4.3-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user