public function addSuccessFlash(Event $event) { if (!isset(self::$successMessages[$event->getName()])) { throw new \InvalidArgumentException('This event does not correspond to a known flash message'); } $this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$event->getName()])); }
/** * Build action event with objects mapped from cause event * * @access public * @param mixed $name * @param Event $mappedEvent (default: null) * @param array $mappedObjects (default: array()) * @return Event */ public function buildActionEvent(ActionEventInterface $actionEvent, Event $mappedEvent) { $mappedObjects = $actionEvent->getObjects(); if (!($mappedEventMap = $this->getEventMap($mappedEvent->getName()))) { throw new \InvalidArgumentException('Undefined mapped event "' . $mappedEvent->getName() . '"'); } if (!($eventMap = $this->getEventMap($actionEvent->getName()))) { throw new \InvalidArgumentException('Undefined action event "' . $actionEvent->getName() . '"'); } $eventClass = $eventMap->getClass(); $event = new $eventClass(); foreach ($eventMap->getSetters() as $method => $setterMeta) { $field = $setterMeta['field']; $value = null; if (isset($mappedObjects[$field])) { $value = $mappedObjects[$field]; } else { foreach ($mappedEventMap->getGetters() as $getterMethod => $getterMeta) { if ($setterMeta['field'] == $getterMeta['field']) { $value = $mappedEvent->{$getterMethod}(); break; } } } if ($value) { $isFunction = 'is_' . $setterMeta['type']; $validObject = false; if (function_exists($isFunction) && $isFunction($value)) { $validObject = true; } elseif ($value instanceof $setterMeta['type']) { $validObject = true; } if ($validObject) { $event->{$method}($value); continue; } } if ($setterMeta['required']) { throw new \UnexpectedValueException(sprintf('Not found object for method "%s" of the event "%s" (with event name "%s")', $method, $eventClass, $actionEvent->getName())); } } return $event; }
public function addSuccessFlash(Event $event, $eventName = null) { // BC for SF < 2.4 if (null === $eventName) { $eventName = $event->getName(); } if (!isset(self::$successMessages[$eventName])) { throw new \InvalidArgumentException('This event does not correspond to a known flash message'); } $this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$eventName])); }
public function getTemplateConfigName(Event $event = null) { switch ($event->getName()) { case MailerBundleEvents::NOTIFICATIONS_PASSWORD_RESET: return 'notification.password_reset'; case MailerBundleEvents::NOTIFICATIONS_PASSWORD_CONFIRM: return 'notification.password_confirm'; default: throw new \Exception('Unsupported event.'); } }
/** * Filters a value by calling all listeners of a given event. * * @param Event $event A Event instance * @param mixed $value The value to be filtered * * @return Event The Event instance */ public function filter(Event $event, $value) { foreach ($this->getListeners($event->getName()) as $listener) { if (null !== $this->logger) { $this->logger->debug(sprintf('Notifying (filter) event "%s" to listener "%s"', $event->getName(), $this->listenerToString($listener))); } $value = call_user_func($listener, $event, $value); } $event->setReturnValue($value); return $event; }
public function handleEvent(Event $event) { $rules = $this->ruleManager->findRulesByEventName($event->getName()); if (sizeof($rules)) { foreach ($rules as $rule) { if ($this->evaluateRule($rule, $event)) { $this->dispatchActionEvents($rule, $event); } } } return $event; }
protected function brocast(Event $event) { $eventName = $event->getName(); $listeners = []; foreach ($this->events[$eventName] as &$eventGroup) { foreach ($eventGroup as $listenerArray) { list($listener, $priority) = $listenerArray; $listeners[$priority][] = $listener; } } krsort($listeners); $processCount = 0; foreach ($listeners as $listener) { foreach ($listener as $callback) { if ($event && $event->isPropagationStopped()) { return $processCount; } $callback($event); $processCount++; } } return $processCount; }
public function testSetName() { $this->event->setName('foo'); $this->assertEquals('foo', $this->event->getName()); }
public function testLegacySetName() { $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); $this->event->setName('foo'); $this->assertEquals('foo', $this->event->getName()); }
/** * Serialize the event data and publish it to the redis queue. * * @param Event $event * * @return Event */ public function dispatchAsync(Event $event = null) { $this->getMqService()->publish($event->getName(), serialize($event)); return $event; }
protected function getTestName(Event $e) { if ($e instanceof TestEvent || $e instanceof FailEvent) { $test = $e->getTest(); return method_exists($test, 'getSignature') ? $test->getSignature() : get_class($test) . ":{$test->getName(false)}"; } elseif ($e instanceof SuiteEvent) { return $e->getSuite()->getName(); } else { return $e->getName(); } }
/** * Handle Step Events & Fire Associated Hooks. * * @param Event $event event */ public function fireStepHooks(Event $event) { switch ($event->getName()) { case 'step.run.before': $hookName = 'step.before'; break; case 'step.run.after': $hookName = 'step.after'; break; } $step = $event->getSubject(); $tagsFilter = $this->tagsFilter; $nameFilter = $this->nameFilter; $this->fireHooks($event, $hookName, function ($hook) use($step, $tagsFilter) { return $tagsFilter->isStepMatchFilter($step, $hook[0]); }, function ($hook) use($step, $nameFilter) { return $nameFilter->isStepMatchFilter($step, $hook[0]); }); }
protected function addCall(Event $event, $listener, $type) { $listener = $this->listenerToString($listener); if (null !== $this->logger) { $this->logger->debug(sprintf('Notified event "%s" to listener "%s" (%s)', $event->getName(), $listener, $type)); } $this->called[$event->getName() . '.' . $listener] = array('event' => $event->getName(), 'caller' => null !== $event->getSubject() ? get_class($event->getSubject()) : null, 'listener' => $listener); }
public function onCatalogDEvent(Event $event) { $this->logger->debug(sprintf('Fired event "%s"', $event->getName())); }
public function recordNotification(Event $event) { $this->lastNotification = $event->getName(); }
/** * Proxies event to the listener. * * @param Event $event * @param null|string $eventName */ public function listenEvent(Event $event, $eventName = null) { $eventName = $eventName ?: $event->getName(); $this->listener->listenEvent($this, $event, $eventName); }