updated packages
This commit is contained in:
@@ -39,8 +39,8 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->logger = $logger;
|
||||
$this->wrappedListeners = array();
|
||||
$this->orphanedEvents = array();
|
||||
$this->wrappedListeners = [];
|
||||
$this->orphanedEvents = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,10 +164,10 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
public function getCalledListeners()
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
$called = array();
|
||||
$called = [];
|
||||
foreach ($this->callStack as $listener) {
|
||||
list($eventName) = $this->callStack->getInfo();
|
||||
|
||||
@@ -186,14 +186,14 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
$allListeners = $this->getListeners();
|
||||
} catch (\Exception $e) {
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->info('An exception was thrown while getting the uncalled listeners.', array('exception' => $e));
|
||||
$this->logger->info('An exception was thrown while getting the uncalled listeners.', ['exception' => $e]);
|
||||
}
|
||||
|
||||
// unable to retrieve the uncalled listeners
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
$notCalled = array();
|
||||
$notCalled = [];
|
||||
foreach ($allListeners as $eventName => $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
$called = false;
|
||||
@@ -216,7 +216,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
}
|
||||
}
|
||||
|
||||
uasort($notCalled, array($this, 'sortNotCalledListeners'));
|
||||
uasort($notCalled, [$this, 'sortNotCalledListeners']);
|
||||
|
||||
return $notCalled;
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
public function reset()
|
||||
{
|
||||
$this->callStack = null;
|
||||
$this->orphanedEvents = array();
|
||||
$this->orphanedEvents = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +279,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
$this->wrappedListeners[$eventName][] = $wrappedListener;
|
||||
$this->dispatcher->removeListener($eventName, $listener);
|
||||
$this->dispatcher->addListener($eventName, $wrappedListener, $priority);
|
||||
$this->callStack->attach($wrappedListener, array($eventName));
|
||||
$this->callStack->attach($wrappedListener, [$eventName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,17 +297,13 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
$this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority);
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$context = array('event' => $eventName, 'listener' => $listener->getPretty());
|
||||
$context = ['event' => $eventName, 'listener' => $listener->getPretty()];
|
||||
}
|
||||
|
||||
if ($listener->wasCalled()) {
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug('Notified event "{event}" to listener "{listener}".', $context);
|
||||
}
|
||||
|
||||
if (!isset($this->called[$eventName])) {
|
||||
$this->called[$eventName] = new \SplObjectStorage();
|
||||
}
|
||||
} else {
|
||||
$this->callStack->detach($listener);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class WrappedListener
|
||||
private $dispatcher;
|
||||
private $pretty;
|
||||
private $stub;
|
||||
private $priority;
|
||||
private static $hasClassStub;
|
||||
|
||||
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||
@@ -94,21 +95,24 @@ class WrappedListener
|
||||
$this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'event' => $eventName,
|
||||
'priority' => null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null,
|
||||
'priority' => null !== $this->priority ? $this->priority : (null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null),
|
||||
'pretty' => $this->pretty,
|
||||
'stub' => $this->stub,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$dispatcher = $this->dispatcher ?: $dispatcher;
|
||||
|
||||
$this->called = true;
|
||||
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
|
||||
|
||||
$e = $this->stopwatch->start($this->name, 'event_listener');
|
||||
|
||||
($this->listener)($event, $eventName, $this->dispatcher ?: $dispatcher);
|
||||
($this->listener)($event, $eventName, $dispatcher);
|
||||
|
||||
if ($e->isStarted()) {
|
||||
$e->stop();
|
||||
|
||||
@@ -28,7 +28,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
protected $listenerTag;
|
||||
protected $subscriberTag;
|
||||
|
||||
private $hotPathEvents = array();
|
||||
private $hotPathEvents = [];
|
||||
private $hotPathTagName;
|
||||
|
||||
public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber')
|
||||
@@ -63,10 +63,10 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
if (!isset($event['method'])) {
|
||||
$event['method'] = 'on'.preg_replace_callback(array(
|
||||
$event['method'] = 'on'.preg_replace_callback([
|
||||
'/(?<=\b)[a-z]/i',
|
||||
'/[^a-z0-9]/i',
|
||||
), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
|
||||
], function ($matches) { return strtoupper($matches[0]); }, $event['event']);
|
||||
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
|
||||
|
||||
if (null !== ($class = $container->getDefinition($id)->getClass()) && ($r = $container->getReflectionClass($class, false)) && !$r->hasMethod($event['method']) && $r->hasMethod('__invoke')) {
|
||||
@@ -74,7 +74,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
$definition->addMethodCall('addListener', array($event['event'], array(new ServiceClosureArgument(new Reference($id)), $event['method']), $priority));
|
||||
$definition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]);
|
||||
|
||||
if (isset($this->hotPathEvents[$event['event']])) {
|
||||
$container->getDefinition($id)->addTag($this->hotPathTagName);
|
||||
@@ -101,14 +101,14 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
ExtractingEventDispatcher::$subscriber = $class;
|
||||
$extractingDispatcher->addSubscriber($extractingDispatcher);
|
||||
foreach ($extractingDispatcher->listeners as $args) {
|
||||
$args[1] = array(new ServiceClosureArgument(new Reference($id)), $args[1]);
|
||||
$args[1] = [new ServiceClosureArgument(new Reference($id)), $args[1]];
|
||||
$definition->addMethodCall('addListener', $args);
|
||||
|
||||
if (isset($this->hotPathEvents[$args[0]])) {
|
||||
$container->getDefinition($id)->addTag('container.hot_path');
|
||||
$container->getDefinition($id)->addTag($this->hotPathTagName);
|
||||
}
|
||||
}
|
||||
$extractingDispatcher->listeners = array();
|
||||
$extractingDispatcher->listeners = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,18 +118,18 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
*/
|
||||
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
|
||||
{
|
||||
public $listeners = array();
|
||||
public $listeners = [];
|
||||
|
||||
public static $subscriber;
|
||||
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
{
|
||||
$this->listeners[] = array($eventName, $listener[1], $priority);
|
||||
$this->listeners[] = [$eventName, $listener[1], $priority];
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
$callback = array(self::$subscriber, 'getSubscribedEvents');
|
||||
$callback = [self::$subscriber, 'getSubscribedEvents'];
|
||||
|
||||
return $callback();
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace Symfony\Component\EventDispatcher;
|
||||
*/
|
||||
class EventDispatcher implements EventDispatcherInterface
|
||||
{
|
||||
private $listeners = array();
|
||||
private $sorted = array();
|
||||
private $listeners = [];
|
||||
private $sorted = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -54,7 +54,7 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
{
|
||||
if (null !== $eventName) {
|
||||
if (empty($this->listeners[$eventName])) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!isset($this->sorted[$eventName])) {
|
||||
@@ -166,12 +166,12 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
{
|
||||
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
||||
if (\is_string($params)) {
|
||||
$this->addListener($eventName, array($subscriber, $params));
|
||||
$this->addListener($eventName, [$subscriber, $params]);
|
||||
} elseif (\is_string($params[0])) {
|
||||
$this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
|
||||
$this->addListener($eventName, [$subscriber, $params[0]], isset($params[1]) ? $params[1] : 0);
|
||||
} else {
|
||||
foreach ($params as $listener) {
|
||||
$this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
|
||||
$this->addListener($eventName, [$subscriber, $listener[0]], isset($listener[1]) ? $listener[1] : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,10 +185,10 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
||||
if (\is_array($params) && \is_array($params[0])) {
|
||||
foreach ($params as $listener) {
|
||||
$this->removeListener($eventName, array($subscriber, $listener[0]));
|
||||
$this->removeListener($eventName, [$subscriber, $listener[0]]);
|
||||
}
|
||||
} else {
|
||||
$this->removeListener($eventName, array($subscriber, \is_string($params) ? $params : $params[0]));
|
||||
$this->removeListener($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
private function sortListeners($eventName)
|
||||
{
|
||||
krsort($this->listeners[$eventName]);
|
||||
$this->sorted[$eventName] = array();
|
||||
$this->sorted[$eventName] = [];
|
||||
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
foreach ($listeners as $k => $listener) {
|
||||
|
||||
@@ -36,9 +36,9 @@ interface EventSubscriberInterface
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
|
||||
* * ['eventName' => 'methodName']
|
||||
* * ['eventName' => ['methodName', $priority]]
|
||||
* * ['eventName' => [['methodName1', $priority], ['methodName2']]]
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
|
||||
* @param mixed $subject The subject of the event, usually an object or a callable
|
||||
* @param array $arguments Arguments to store in the event
|
||||
*/
|
||||
public function __construct($subject = null, array $arguments = array())
|
||||
public function __construct($subject = null, array $arguments = [])
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->arguments = $arguments;
|
||||
@@ -95,7 +95,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArguments(array $args = array())
|
||||
public function setArguments(array $args = [])
|
||||
{
|
||||
$this->arguments = $args;
|
||||
|
||||
@@ -111,7 +111,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
|
||||
*/
|
||||
public function hasArgument($key)
|
||||
{
|
||||
return array_key_exists($key, $this->arguments);
|
||||
return \array_key_exists($key, $this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,15 +47,15 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
|
||||
public function testInitialState()
|
||||
{
|
||||
$this->assertEquals(array(), $this->dispatcher->getListeners());
|
||||
$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', array($this->listener, 'preFoo'));
|
||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
||||
$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));
|
||||
@@ -73,15 +73,15 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$listener2->name = '2';
|
||||
$listener3->name = '3';
|
||||
|
||||
$this->dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10);
|
||||
$this->dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10);
|
||||
$this->dispatcher->addListener('pre.foo', array($listener3, 'preFoo'));
|
||||
$this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10);
|
||||
$this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']);
|
||||
|
||||
$expected = array(
|
||||
array($listener2, 'preFoo'),
|
||||
array($listener3, 'preFoo'),
|
||||
array($listener1, 'preFoo'),
|
||||
);
|
||||
$expected = [
|
||||
[$listener2, 'preFoo'],
|
||||
[$listener3, 'preFoo'],
|
||||
[$listener1, 'preFoo'],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
|
||||
}
|
||||
@@ -102,10 +102,10 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$this->dispatcher->addListener('post.foo', $listener5);
|
||||
$this->dispatcher->addListener('post.foo', $listener6, 10);
|
||||
|
||||
$expected = array(
|
||||
'pre.foo' => array($listener3, $listener2, $listener1),
|
||||
'post.foo' => array($listener6, $listener5, $listener4),
|
||||
);
|
||||
$expected = [
|
||||
'pre.foo' => [$listener3, $listener2, $listener1],
|
||||
'post.foo' => [$listener6, $listener5, $listener4],
|
||||
];
|
||||
|
||||
$this->assertSame($expected, $this->dispatcher->getListeners());
|
||||
}
|
||||
@@ -126,8 +126,8 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
|
||||
public function testDispatch()
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
||||
$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);
|
||||
@@ -157,8 +157,8 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
// 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', array($this->listener, 'postFoo'), 10);
|
||||
$this->dispatcher->addListener('post.foo', array($otherListener, 'postFoo'));
|
||||
$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);
|
||||
@@ -166,7 +166,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
|
||||
public function testDispatchByPriority()
|
||||
{
|
||||
$invoked = array();
|
||||
$invoked = [];
|
||||
$listener1 = function () use (&$invoked) {
|
||||
$invoked[] = '1';
|
||||
};
|
||||
@@ -180,7 +180,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||
$this->dispatcher->dispatch(self::preFoo);
|
||||
$this->assertEquals(array('3', '2', '1'), $invoked);
|
||||
$this->assertEquals(['3', '2', '1'], $invoked);
|
||||
}
|
||||
|
||||
public function testRemoveListener()
|
||||
@@ -258,7 +258,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
public function testEventReceivesTheDispatcherInstanceAsArgument()
|
||||
{
|
||||
$listener = new TestWithDispatcher();
|
||||
$this->dispatcher->addListener('test', array($listener, 'foo'));
|
||||
$this->dispatcher->addListener('test', [$listener, 'foo']);
|
||||
$this->assertNull($listener->name);
|
||||
$this->assertNull($listener->dispatcher);
|
||||
$this->dispatcher->dispatch('test');
|
||||
@@ -295,7 +295,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$listener = function () {};
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->dispatcher->removeListener('foo', $listener);
|
||||
$this->assertSame(array(), $this->dispatcher->getListeners());
|
||||
$this->assertSame([], $this->dispatcher->getListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
|
||||
@@ -307,7 +307,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
public function testHasListenersIsLazy()
|
||||
{
|
||||
$called = 0;
|
||||
$listener = array(function () use (&$called) { ++$called; }, 'onFoo');
|
||||
$listener = [function () use (&$called) { ++$called; }, 'onFoo'];
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
@@ -322,7 +322,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
|
||||
return new TestWithDispatcher();
|
||||
};
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertSame(0, $called);
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
@@ -334,14 +334,14 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
|
||||
$this->dispatcher->addListener('foo', array($test, 'foo'));
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo']);
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
||||
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
}
|
||||
|
||||
@@ -350,12 +350,12 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
||||
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo')));
|
||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
||||
$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', array($test, 'foo'), 5);
|
||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo')));
|
||||
$this->dispatcher->addListener('foo', [$test, 'foo'], 5);
|
||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', [$factory, 'foo']));
|
||||
}
|
||||
|
||||
public function testGetLazyListeners()
|
||||
@@ -363,12 +363,12 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
||||
$this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo'));
|
||||
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||
$this->assertSame([[$test, 'foo']], $this->dispatcher->getListeners('foo'));
|
||||
|
||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
||||
$this->dispatcher->addListener('bar', array($factory, 'foo'), 3);
|
||||
$this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners());
|
||||
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||
$this->dispatcher->addListener('bar', [$factory, 'foo'], 3);
|
||||
$this->assertSame(['bar' => [[$test, 'foo']]], $this->dispatcher->getListeners());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ class TestEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array('pre.foo' => 'preFoo', 'post.foo' => 'postFoo');
|
||||
return ['pre.foo' => 'preFoo', 'post.foo' => 'postFoo'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,10 +423,10 @@ class TestEventSubscriberWithPriorities implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'pre.foo' => array('preFoo', 10),
|
||||
'post.foo' => array('postFoo'),
|
||||
);
|
||||
return [
|
||||
'pre.foo' => ['preFoo', 10],
|
||||
'post.foo' => ['postFoo'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,9 +434,9 @@ class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterfa
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array('pre.foo' => array(
|
||||
array('preFoo1'),
|
||||
array('preFoo2', 10),
|
||||
));
|
||||
return ['pre.foo' => [
|
||||
['preFoo1'],
|
||||
['preFoo2', 10],
|
||||
]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher->addSubscriber($subscriber);
|
||||
$listeners = $dispatcher->getListeners('foo');
|
||||
$this->assertCount(1, $listeners);
|
||||
$this->assertSame(array($subscriber, 'call'), $listeners[0]);
|
||||
$this->assertSame([$subscriber, 'call'], $listeners[0]);
|
||||
|
||||
$tdispatcher->removeSubscriber($subscriber);
|
||||
$this->assertCount(0, $dispatcher->getListeners('foo'));
|
||||
@@ -112,16 +112,16 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$listeners = $tdispatcher->getNotCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
unset($listeners[0]['stub']);
|
||||
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
|
||||
$this->assertEquals([], $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners);
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
|
||||
$listeners = $tdispatcher->getCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
unset($listeners[0]['stub']);
|
||||
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
|
||||
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
|
||||
$this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners);
|
||||
$this->assertEquals([], $tdispatcher->getNotCalledListeners());
|
||||
}
|
||||
|
||||
public function testClearCalledListeners()
|
||||
@@ -135,8 +135,8 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$listeners = $tdispatcher->getNotCalledListeners();
|
||||
$this->assertArrayHasKey('stub', $listeners[0]);
|
||||
unset($listeners[0]['stub']);
|
||||
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
|
||||
$this->assertEquals([], $tdispatcher->getCalledListeners());
|
||||
$this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners);
|
||||
}
|
||||
|
||||
public function testDispatchAfterReset()
|
||||
@@ -178,7 +178,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher->dispatch('foo');
|
||||
$events = $tdispatcher->getOrphanedEvents();
|
||||
$this->assertCount(1, $events);
|
||||
$this->assertEquals(array('foo'), $events);
|
||||
$this->assertEquals(['foo'], $events);
|
||||
}
|
||||
|
||||
public function testItDoesNotReturnHandledEvents()
|
||||
@@ -199,8 +199,8 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher->addListener('foo', $listener1 = function () {});
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
|
||||
$logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
|
||||
$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');
|
||||
}
|
||||
@@ -214,16 +214,16 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', array('event' => 'foo', 'listener' => 'closure'));
|
||||
$logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', array('event' => 'foo', 'listener' => 'closure'));
|
||||
$logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', array('event' => 'foo', 'listener' => 'closure'));
|
||||
$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('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');
|
||||
}
|
||||
|
||||
public function testDispatchCallListeners()
|
||||
{
|
||||
$called = array();
|
||||
$called = [];
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
|
||||
@@ -232,7 +232,7 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
|
||||
$tdispatcher->dispatch('foo');
|
||||
|
||||
$this->assertSame(array('foo2', 'foo1'), $called);
|
||||
$this->assertSame(['foo2', 'foo1'], $called);
|
||||
}
|
||||
|
||||
public function testDispatchNested()
|
||||
@@ -300,6 +300,6 @@ class EventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array('foo' => 'call');
|
||||
return ['foo' => 'call'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,16 @@ class WrappedListenerTest extends TestCase
|
||||
|
||||
public function provideListenersToDescribe()
|
||||
{
|
||||
return array(
|
||||
array(new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'),
|
||||
array(array(new FooListener(), 'listen'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
|
||||
array(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
|
||||
array('var_dump', 'var_dump'),
|
||||
array(function () {}, 'closure'),
|
||||
array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'),
|
||||
array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'),
|
||||
array(\Closure::fromCallable(function () {}), 'closure'),
|
||||
);
|
||||
return [
|
||||
[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'],
|
||||
['var_dump', 'var_dump'],
|
||||
[function () {}, 'closure'],
|
||||
[\Closure::fromCallable([new FooListener(), 'listen']), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
|
||||
[\Closure::fromCallable(['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic']), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'],
|
||||
[\Closure::fromCallable(function () {}), 'closure'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ class RegisterListenersPassTest extends TestCase
|
||||
|
||||
public function testValidEventSubscriber()
|
||||
{
|
||||
$services = array(
|
||||
'my_event_subscriber' => array(0 => array()),
|
||||
);
|
||||
$services = [
|
||||
'my_event_subscriber' => [0 => []],
|
||||
];
|
||||
|
||||
$builder = new ContainerBuilder();
|
||||
$eventDispatcherDefinition = $builder->register('event_dispatcher');
|
||||
@@ -50,16 +50,16 @@ class RegisterListenersPassTest extends TestCase
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($builder);
|
||||
|
||||
$expectedCalls = array(
|
||||
array(
|
||||
$expectedCalls = [
|
||||
[
|
||||
'addListener',
|
||||
array(
|
||||
[
|
||||
'event',
|
||||
array(new ServiceClosureArgument(new Reference('my_event_subscriber')), 'onEvent'),
|
||||
[new ServiceClosureArgument(new Reference('my_event_subscriber')), 'onEvent'],
|
||||
0,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedCalls, $eventDispatcherDefinition->getMethodCalls());
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class RegisterListenersPassTest extends TestCase
|
||||
public function testAbstractEventListener()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_listener', array());
|
||||
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_listener', []);
|
||||
$container->register('event_dispatcher', 'stdClass');
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
@@ -84,7 +84,7 @@ class RegisterListenersPassTest extends TestCase
|
||||
public function testAbstractEventSubscriber()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array());
|
||||
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', []);
|
||||
$container->register('event_dispatcher', 'stdClass');
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
@@ -96,23 +96,23 @@ class RegisterListenersPassTest extends TestCase
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->setParameter('subscriber.class', 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService');
|
||||
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array());
|
||||
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', []);
|
||||
$container->register('event_dispatcher', 'stdClass');
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($container);
|
||||
|
||||
$definition = $container->getDefinition('event_dispatcher');
|
||||
$expectedCalls = array(
|
||||
array(
|
||||
$expectedCalls = [
|
||||
[
|
||||
'addListener',
|
||||
array(
|
||||
[
|
||||
'event',
|
||||
array(new ServiceClosureArgument(new Reference('foo')), 'onEvent'),
|
||||
[new ServiceClosureArgument(new Reference('foo')), 'onEvent'],
|
||||
0,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedCalls, $definition->getMethodCalls());
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ class RegisterListenersPassTest extends TestCase
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', SubscriberService::class)->addTag('kernel.event_subscriber', array());
|
||||
$container->register('foo', SubscriberService::class)->addTag('kernel.event_subscriber', []);
|
||||
$container->register('event_dispatcher', 'stdClass');
|
||||
|
||||
(new RegisterListenersPass())->setHotPathEvents(array('event'))->process($container);
|
||||
(new RegisterListenersPass())->setHotPathEvents(['event'])->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('foo')->hasTag('container.hot_path'));
|
||||
}
|
||||
@@ -135,7 +135,7 @@ class RegisterListenersPassTest extends TestCase
|
||||
public function testEventSubscriberUnresolvableClassName()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array());
|
||||
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', []);
|
||||
$container->register('event_dispatcher', 'stdClass');
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
@@ -145,41 +145,41 @@ class RegisterListenersPassTest extends TestCase
|
||||
public function testInvokableEventListener()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('foo', \stdClass::class)->addTag('kernel.event_listener', array('event' => 'foo.bar'));
|
||||
$container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', array('event' => 'foo.bar'));
|
||||
$container->register('baz', InvokableListenerService::class)->addTag('kernel.event_listener', array('event' => 'event'));
|
||||
$container->register('foo', \stdClass::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']);
|
||||
$container->register('bar', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'foo.bar']);
|
||||
$container->register('baz', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => 'event']);
|
||||
$container->register('event_dispatcher', \stdClass::class);
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($container);
|
||||
|
||||
$definition = $container->getDefinition('event_dispatcher');
|
||||
$expectedCalls = array(
|
||||
array(
|
||||
$expectedCalls = [
|
||||
[
|
||||
'addListener',
|
||||
array(
|
||||
[
|
||||
'foo.bar',
|
||||
array(new ServiceClosureArgument(new Reference('foo')), 'onFooBar'),
|
||||
[new ServiceClosureArgument(new Reference('foo')), 'onFooBar'],
|
||||
0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'addListener',
|
||||
array(
|
||||
[
|
||||
'foo.bar',
|
||||
array(new ServiceClosureArgument(new Reference('bar')), '__invoke'),
|
||||
[new ServiceClosureArgument(new Reference('bar')), '__invoke'],
|
||||
0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'addListener',
|
||||
array(
|
||||
[
|
||||
'event',
|
||||
array(new ServiceClosureArgument(new Reference('baz')), 'onEvent'),
|
||||
[new ServiceClosureArgument(new Reference('baz')), 'onEvent'],
|
||||
0,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedCalls, $definition->getMethodCalls());
|
||||
}
|
||||
}
|
||||
@@ -188,9 +188,9 @@ class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubsc
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'event' => 'onEvent',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class GenericEventTest extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
$this->subject = new \stdClass();
|
||||
$this->event = new GenericEvent($this->subject, array('name' => 'Event'));
|
||||
$this->event = new GenericEvent($this->subject, ['name' => 'Event']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ class GenericEventTest extends TestCase
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$this->assertEquals($this->event, new GenericEvent($this->subject, array('name' => 'Event')));
|
||||
$this->assertEquals($this->event, new GenericEvent($this->subject, ['name' => 'Event']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,20 +55,20 @@ class GenericEventTest extends TestCase
|
||||
public function testGetArguments()
|
||||
{
|
||||
// test getting all
|
||||
$this->assertSame(array('name' => 'Event'), $this->event->getArguments());
|
||||
$this->assertSame(['name' => 'Event'], $this->event->getArguments());
|
||||
}
|
||||
|
||||
public function testSetArguments()
|
||||
{
|
||||
$result = $this->event->setArguments(array('foo' => 'bar'));
|
||||
$this->assertAttributeSame(array('foo' => 'bar'), 'arguments', $this->event);
|
||||
$result = $this->event->setArguments(['foo' => 'bar']);
|
||||
$this->assertAttributeSame(['foo' => 'bar'], 'arguments', $this->event);
|
||||
$this->assertSame($this->event, $result);
|
||||
}
|
||||
|
||||
public function testSetArgument()
|
||||
{
|
||||
$result = $this->event->setArgument('foo2', 'bar2');
|
||||
$this->assertAttributeSame(array('name' => 'Event', 'foo2' => 'bar2'), 'arguments', $this->event);
|
||||
$this->assertAttributeSame(['name' => 'Event', 'foo2' => 'bar2'], 'arguments', $this->event);
|
||||
$this->assertEquals($this->event, $result);
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ class GenericEventTest extends TestCase
|
||||
public function testOffsetSet()
|
||||
{
|
||||
$this->event['foo2'] = 'bar2';
|
||||
$this->assertAttributeSame(array('name' => 'Event', 'foo2' => 'bar2'), 'arguments', $this->event);
|
||||
$this->assertAttributeSame(['name' => 'Event', 'foo2' => 'bar2'], 'arguments', $this->event);
|
||||
}
|
||||
|
||||
public function testOffsetUnset()
|
||||
{
|
||||
unset($this->event['name']);
|
||||
$this->assertAttributeSame(array(), 'arguments', $this->event);
|
||||
$this->assertAttributeSame([], 'arguments', $this->event);
|
||||
}
|
||||
|
||||
public function testOffsetIsset()
|
||||
@@ -127,10 +127,10 @@ class GenericEventTest extends TestCase
|
||||
|
||||
public function testHasIterator()
|
||||
{
|
||||
$data = array();
|
||||
$data = [];
|
||||
foreach ($this->event as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
$this->assertEquals(array('name' => 'Event'), $data);
|
||||
$this->assertEquals(['name' => 'Event'], $data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user