/** * 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; }
/** * 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); } }
/** * {@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()); }
/** * Publish an event * * @param Event $anEvent the event to publish */ public function publish(EventInterface $anEvent) { foreach ($this->initQueue($anEvent->eventType(), []) as $handler) { $handler($anEvent); } foreach ($this->initQueue() as $handler) { $handler($anEvent); } }
/** * @param EventInterface $event * @param EventSubscriberInterface $subscriber */ protected function dispatch(EventInterface $event, EventSubscriberInterface $subscriber) { $subscribedEvents = $subscriber->getSubscribedEvents(); foreach ($subscribedEvents as $eventName => $method) { if ($eventName == $event->getEventName()) { $subscriber->{$method}($event); } } }
protected function dispatchEvent(EventInterface $aEvent, $aOptions = null) { $options = ['listener' => null]; if ($aOptions) { $options = array_replace($options, $aOptions); } $type = $aEvent->getType(); $listeners = $options['listener'] ? [$options['listener']] : (array_key_exists($type, $this->listeners) ? $this->listeners[$type] : []); foreach ($listeners as $listener) { $listener($aEvent); } }
public function emit($eventName, EventInterface $event) { if (isset($this->listeners[$eventName])) { foreach ($this->listeners($eventName) as $listener) { call_user_func_array($listener, array($event, $eventName)); if ($event->isPropagationStopped()) { break; } } } return $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(); } }
/** * @dataProvider triggerEventProvider */ public function testTriggerEvent($result) { $this->event->expects($this->any())->method('trigger')->willReturn($result); $payload = $this->getMock('\\StateMachine\\PayloadInterface'); $state = new State('stateName', [$this->event], [$this->flag]); $this->assertEquals($result, $state->triggerEvent('eventName', $payload)); }
/** * Checks if adding the event would cause the rate limit to be exceeded * @return Boolean */ protected function exceedsRateLimit() : Boolean { $count = $this->repository->count($this->event); $cost = $this->event->getCost(); $limit = $this->limit->getLimit(); return $count->add($cost)->greaterThan($limit); }
/** * Kernel event * * @param EventInterface $event The received event */ public function onKernelResponse($event) { if (HttpKernelInterface::MASTER_REQUEST == $event->getRequestType()) { foreach ($this->statsdClients as $clientName => $client) { $clientInfo = ['name' => $clientName, 'operations' => []]; foreach ($client->getToSend() as $serverKey => $operation) { $this->data['operations']++; $message = $operation['message']; if ($operation) { $clientInfo['operations'][] = ['server' => $serverKey, 'node' => $message->getNode(), 'value' => $message->getValue(), 'sample' => $message->getSampleRate(), 'unit' => $message->getUnit()]; } } $this->data['clients'][] = $clientInfo; } } }
public function __invoke(EventInterface $e) { if (isset($e['mvc.actioncontroller.broker'])) { $this->setHelperBroker($e['mvc.actioncontroller.broker']); } $request = $e->getRequest(); $action = $request->getActionName(); if (null === $action) { $action = 'index'; } $method = $this->_formatActionName($action); $response = $e->getResponse(); $context = $request->getControllerName() . '/' . $request->getActionName(); $response->assign(array(), $context); $this->{$method}($e); $values = $response->getValues(); }
public function handle(EventInterface $e) { $response = $e->getResponse(); $exceptions = $e->getExceptions(); $exception = array_pop($exceptions); $response->assign(array('exception' => $exception), 'error/error'); switch (get_class($exception)) { case $exception instanceof PageNotFoundException: $response->setCode(404); $response->assign('message', 'Page Not Found', 'error/error'); break; default: $response->setCode(500); $response->assign('message', 'An unexpected error occurred', 'error/error'); break; } }
/** * Checks if this event is equal to another * @param EventInterface $event * @return Boolean */ public function equal(EventInterface $event) : Boolean { return new Boolean($this->getId() === $event->getId()); }
public function dispatch(EventInterface $e) { $request = $e->getRequest(); $module = $request->getModuleName(); $controller = $request->getControllerName(); if (empty($module) || $module == 'default') { $module = 'application'; } if (empty($controller)) { $controller = 'index'; } $dirs = $this->getControllerDirectories(); if (!in_array($module, array_keys($dirs))) { $e->setState('error'); $e->addException(new InvalidModuleException()); return; } $dir = $dirs[$module]; $controllerSegment = $this->_normalizeClassName($controller) . 'Controller'; $classFile = $dir . '/' . str_replace('_', '/', $controllerSegment) . '.php'; $className = lcfirst($this->_normalizeClassName($module)) . '\\' . $controllerSegment; if (!file_exists($classFile)) { $e->setState('error'); $e->addException(new ControllerNotFoundException()); return; } include_once $classFile; if (!class_exists($className)) { $e->setState('error'); $e->addException(new ControllerNotFoundException()); return; } $controller = new $className(); if (!is_callable($controller)) { $e->setState('error'); $e->addException(new InvalidControllerException()); return; } try { $controller($e); } catch (\Exception $except) { $e->setState('error'); $e->addException($except); } return $e; }
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()]]; }
public function route(EventInterface $e) { $request = $e->getRequest(); $this->getRouter()->route($request); }
/** * Test that the event properties can be fetched as an array */ public function testCanGetAsArray() { $this->event->setType('event'); $this->assertTrue(is_array($this->event->toArray())); }
public function __construct($request) { parent::__construct($request); $this->rules =& $request->get_sort_by_ref(); }
/** * Converts an event object into an array. * * @param \Phergie\Irc\Event\EventInterface $event * @return array */ public function convert(EventInterface $event) { $connection = $event->getConnection(); $array = array('message' => $event->getMessage(), 'params' => $event->getParams(), 'command' => $event->getCommand(), 'connection' => array('serverHostname' => $connection->getServerHostname(), 'serverPort' => $connection->getServerPort(), 'nickname' => $connection->getNickname(), 'username' => $connection->getUsername(), 'hostname' => $connection->getHostname(), 'servername' => $connection->getServername(), 'realname' => $connection->getRealname())); if ($event instanceof UserEventInterface) { $array['user'] = array('prefix' => $event->getPrefix(), 'nick' => $event->getNick(), 'username' => $event->getUsername(), 'host' => $event->getHost(), 'targets' => $event->getTargets()); } if ($event instanceof CtcpEventInterface) { $array['ctcp'] = array('command' => $event->getCtcpCommand(), 'params' => $event->getCtcpParams()); } return $array; }