4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\EventDispatcher;
13 use Symfony\Component\EventDispatcher\Event;
14 use Symfony\Component\EventDispatcher\EventDispatcher;
17 * Extends Symfony2 event dispatcher with catch-all listeners.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 final class TestworkEventDispatcher extends EventDispatcher
23 const BEFORE_ALL_EVENTS = '*~';
24 const AFTER_ALL_EVENTS = '~*';
29 public function dispatch($eventName, Event $event = null)
31 if (null === $event) {
35 if (method_exists($event, 'setName')) {
36 $event->setName($eventName);
39 $this->doDispatch($this->getListeners($eventName), $eventName, $event);
47 public function getListeners($eventName = null)
49 if (null == $eventName || self::BEFORE_ALL_EVENTS === $eventName) {
50 return parent::getListeners($eventName);
54 parent::getListeners(self::BEFORE_ALL_EVENTS),
55 parent::getListeners($eventName),
56 parent::getListeners(self::AFTER_ALL_EVENTS)