/** * Add an event to this dispatcher, only if it is not existing. * * @param EventInterface $event The event. * * @return Dispatcher This method is chainable. * * @since 2.0 */ public function addEvent(EventInterface $event) { if (!isset($this->events[$event->getName()])) { $this->events[$event->getName()] = $event; } return $this; }
/** * {@inheritdoc} */ public function handle(EventInterface $event) { $name = $event->getName(); $emitter = $event->getEmitter(); $emitter->removeListener($name, $this->listener); return call_user_func_array([$this->listener, 'handle'], func_get_args()); }
/** * Notifies registered for that event callback function * * @param Event $event */ public function dispatch(EventInterface $event) { $eventName = $event->getName(); foreach ($this->getListeners($eventName) as $listener) { call_user_func($listener, $event); } }
/** * Handle an event * * @param EventInterface $event an event * @param string $name the event name * * @throws Exception * @return void */ public function handleEvent($event, $name = null) { // this is used to stay compatible with Symfony 2.3 if (is_null($name)) { $name = $event->getName(); } if (!isset($this->listenedEvents[$name])) { return; } $config = $this->listenedEvents[$name]; $immediateSend = false; $tags = $this->mergeTags($event, $config); // replace placeholders in tags $tags = array_map(function ($tag) use($event, $name) { return $this->replaceConfigPlaceholder($event, $name, $tag); }, $tags); foreach ($config as $conf => $confValue) { // increment if ('increment' === $conf) { $this->increment($this->replaceConfigPlaceholder($event, $name, $confValue), 1, $tags); } elseif ('count' === $conf) { $value = $this->getEventValue($event, 'getValue'); $this->count($this->replaceConfigPlaceholder($event, $name, $confValue), $value, 1, $tags); } elseif ('gauge' === $conf) { $value = $this->getEventValue($event, 'getValue'); $this->gauge($this->replaceConfigPlaceholder($event, $name, $confValue), $value, 1, $tags); } elseif ('set' === $conf) { $value = $this->getEventValue($event, 'getValue'); $this->set($this->replaceConfigPlaceholder($event, $name, $confValue), $value, 1, $tags); } elseif ('timing' === $conf) { $this->addTiming($event, 'getTiming', $this->replaceConfigPlaceholder($event, $name, $confValue), $tags); } elseif ('custom_timing' === $conf and is_array($confValue)) { $this->addTiming($event, $confValue['method'], $this->replaceConfigPlaceholder($event, $name, $confValue['node']), $tags); } elseif ('immediate_send' === $conf) { $immediateSend = $confValue; } elseif ('tags' === $conf) { // nothing } else { throw new Exception("configuration : " . $conf . " not handled by the StatsdBundle or its value is in a wrong format."); } } if (null !== $this->toSendLimit && $this->getToSend()->count() >= $this->toSendLimit) { $immediateSend = true; } if ($immediateSend) { $this->send(); } }
public function filter(EventInterface $event, $value) { foreach ($this->getListeners($event->getName()) as $listener) { $value = call_user_func($listener, $event, $value); } return $value; }
/** * @param EventInterface $event The event instance. */ public function __construct(EventInterface $event) { $this->event = $event; parent::__construct(sprintf('Exception in event "%s".', $event->getName())); }
/** * @param ChannelInterface $channel * @param EventInterface $event * * @return array */ public function format(ChannelInterface $channel, EventInterface $event) { return ['channel' => ['id' => $channel->getId()], 'event' => ['name' => $event->getName(), 'metadata' => $event->getMetadata(), 'data' => $event->getData(), 'tag' => $event->getTag()]]; }