public function __construct($debug, ContainerAwareEventDispatcher $dispatcher) { $this->debug = $debug; $this->dispatcher = $dispatcher; $this->translator = $dispatcher->getContainer()->get("thelia.translator"); $this->hookResults = array(); }
/** * @param $slot * @param Lead|array $lead * * @return string */ public function getDynamicContentForLead($slot, $lead) { $response = $this->campaignEventModel->triggerEvent('dwc.decision', $slot, 'dwc.decision.' . $slot); $content = ''; if (is_array($response) && !empty($response['action']['dwc.push_content'])) { $content = array_shift($response['action']['dwc.push_content']); } else { $data = $this->dynamicContentModel->getSlotContentForLead($slot, $lead); if (!empty($data)) { $content = $data['content']; $dwc = $this->dynamicContentModel->getEntity($data['id']); if ($dwc instanceof DynamicContent) { // Determine a translation based on contact's preferred locale /** @var DynamicContent $translation */ list($ignore, $translation) = $this->dynamicContentModel->getTranslatedEntity($dwc, $lead); if ($translation !== $dwc) { // Use translated version of content $dwc = $translation; $content = $dwc->getContent(); } $this->dynamicContentModel->createStatEntry($dwc, $lead, $slot); $tokenEvent = new TokenReplacementEvent($content, $lead, ['slot' => $slot, 'dynamic_content_id' => $dwc->getId()]); $this->dispatcher->dispatch(DynamicContentEvents::TOKEN_REPLACEMENT, $tokenEvent); $content = $tokenEvent->getContent(); } } } return $content; }
/** * @param \Doctrine\ORM\Event\LifecycleEventArgs $args */ public function postUpdate(LifecycleEventArgs $args) { $entity = $args->getEntity(); if (!$entity instanceof Transaction) { return; } $this->dispatcher->dispatch(PaymentEvents::TRANSACTION_UPDATED, new TransactionUpdatedEvent($entity)); }
protected function setUpListener() { $that = $this; $overrider = new OMClassOverrider(PropelExtendingTest::$map); EventDispatcherProxy::setDispatcherGetter(function () use($that, $overrider) { $c = $that->getContainer(); $d = new ContainerAwareEventDispatcher($c); $d->addListener('om.detect', array($overrider, 'onDetectionRequest')); return $d; }); return $overrider; }
protected function boot() { $dispatcher = new EventDispatcher($this->container); $resolver = new ControllerResolver($this->container); $this->httpKernel = new HttpKernel($dispatcher, $resolver); $this->legacyKernel = new LegacyIntranetKernel($dispatcher); $locator = new FileLocator(array(__DIR__ . '/config')); $loader = new YamlFileLoader($locator); $collection = $loader->load('routes.yml'); $context = new RequestContext(); $matcher = new UrlMatcher($collection, $context); $dispatcher->addSubscriber(new RouterListener($matcher, $context)); }
/** * Generate admin menu navigation object * * @return \Knp\Menu\ItemInterface */ public function adminMenu() { static $adminMenu; if (empty($adminMenu)) { $loader = new ArrayLoader($this->factory); //dispatch the MENU_BUILD event to retrieve bundle menu items $event = new MenuEvent($this->menuHelper, 'admin'); $this->dispatcher->dispatch(CoreEvents::BUILD_MENU, $event); $menuItems = $event->getMenuItems(); $adminMenu = $loader->load($menuItems); } return $adminMenu; }
public function dispatch($eventName, Event $event = null) { if ($event instanceof LoggableEventInterface) { $this->getContainer()->get('logger')->addInfo($eventName, $event->getLogContext()); } return parent::dispatch($eventName, $event); }
/** * {@inheritDoc} */ public function get($key) { $key = $this->updateCacheKey($key); $result = $this->getActiveImplementation()->get($key); //Parse result to retrieve it raw if ($result) { try { $cacheItemStore = new CacheItemStore(); $cacheItemStore->hydrateFromCacheData($result); $cacheItemStore->getData(); $result = $cacheItemStore->getData(); } catch (CorruptedDataException $e) { $result = null; } } //Throwing event if ($result) { //Dispatch memcache hit event $event = new CacheHitEvent($this->getActiveImplementation()->getName(), $key, $result); $this->eventDispatcher->dispatch("urodoz.events.cachehit", $event); } else { //Dispatch memcache missed hit event $event = new MissedCacheHitEvent($this->getActiveImplementation()->getName(), $key); $this->eventDispatcher->dispatch("urodoz.events.missed_cachehit", $event); } return $result; }
/** * {@inheritdoc} */ public function dispatch($eventName, Event $event = null) { if ($this->disabled) { return $event; } return parent::dispatch($eventName, $event); }
/** * {@inheritDoc} * * Lazily loads listeners for this event from the dependency injection * container. * * @throws \InvalidArgumentException if the service is not defined */ public function dispatch($eventName, Event $event = null) { if ($this->interceptAsyncEvent($eventName, $event) != null) { $this->getContainer()->get('logger')->info(sprintf('Async event intercepted[%s]!', $eventName)); } return parent::dispatch($eventName, $event); }
/** * @param string $eventName * @param Event $event * @return Event */ public function dispatch($eventName, Event $event = null) { if (empty($event)) { throw new RuntimeException('You have to pass an Event into EventDispatcher::dispatch'); } foreach ($this->catchall as $dispatcher) { $dispatcher->dispatch($eventName, $event); } return parent::dispatch($eventName, $event); }
public function addListenerService($eventName, $callback, $priority = 0) { if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); } $bundle = $this->kernel->getBundleByServiceId($eventName[0]); // skip inactive module bundles if (!$bundle || !$bundle instanceof AbstractModule || $bundle instanceof AbstractModule && $this->kernel->isModuleBundleActive($bundle)) { parent::addListenerService($eventName, $callback, $priority); } }
/** * @param $name * * @return mixed */ private function buildMenu($name) { static $menus = array(); if (!isset($menus[$name])) { $loader = new ArrayLoader($this->factory); //dispatch the MENU_BUILD event to retrieve bundle menu items $event = new MenuEvent($this->menuHelper, $name); $this->dispatcher->dispatch(CoreEvents::BUILD_MENU, $event); $menuItems = $event->getMenuItems(); $menus[$name] = $loader->load($menuItems); } return $menus[$name]; }
/** * When loading listener services, store in a separate index the queue to which service is limited * @param string $eventName */ protected function lazyLoad($eventName) { parent::lazyLoad($eventName); if (isset($this->listenerIds[$eventName])) { foreach ($this->listenerIds[$eventName] as $args) { list($serviceId, $method, $priority, $queueName) = $args; if ($queueName != null) { $listener = $this->container->get($serviceId); $key = $serviceId . '.' . $method; $this->listeners[$eventName][$key] = array($listener, $queueName); } } } }
/** * @param Transaction $transaction * @throws Exception */ public function processTransaction(Transaction $transaction) { $method = $transaction->getMethod(); if (false === $this->methodIsAvailable($method)) { throw new Exception(sprintf('The payment method "%s" is not available', $method->getName())); } switch (true) { case $transaction instanceof CreditCardTransaction: $this->processCreditCardTransaction($transaction); break; case $transaction instanceof PaypalTransaction: $this->processPaypalTransaction($transaction); break; default: throw new Exception(sprintf('Unhandled Transaction class "%s"', get_class($transaction))); } // Persist processed transaction $this->em->persist($transaction); $this->em->flush(); // dispatch TransactionCreated event $this->dispatcher->dispatch(PaymentEvents::TRANSACTION_PROCESSED, new TransactionProcessedEvent($transaction)); }
/** * Processes the form. * * @param NotificationInterface $notification * @param array $parameters * @param String $method * * @return NotificationInterface * * @throws \PROCERGS\LoginCidadao\CoreBundle\Exception\Notification\InvalidFormException */ private function processForm(NotificationInterface $notification, array $parameters, $method = "PUT", PersonInterface $person = null) { $form = $this->formFactory->create($this->notificationType, $notification, compact('method')); $form->submit($parameters, 'PATCH' !== $method); if ($form->isValid()) { $notification = $form->getData(); $notificationEvent = new NotificationEvent($notification); $this->dispatcher->dispatch(NotificationEvents::NOTIFICATION_INITIALIZE, $notificationEvent); if (null !== $person && $notification->getPerson()->getId() !== $person->getId()) { throw new AccessDeniedHttpException(); } if (null === $notification->getHtmlTemplate()) { $notification->setHtmlTemplate(self::renderHtmlByCategory($notification->getCategory(), $notification->getPlaceholders(), $notification->getTitle(), $notification->getShortText())); } $this->om->persist($notification); $this->om->flush($notification); $this->dispatcher->dispatch(NotificationEvents::NOTIFICATION_SUCCESS, $notificationEvent); $this->dispatcher->dispatch(NotificationEvents::NOTIFICATION_COMPLETED, $notificationEvent); return $notification; } throw new InvalidFormException('Invalid submitted data ' . print_r($this->getErrorMessages($form), 1), $form); }
/** * {@inheritdoc} */ public function removeListener($eventName, $listener) { $this->_wrappedDispatcher->removeListener($eventName, $listener); }
/** * @param ContainerInterface $container * @return \Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher */ public function createEventDispatcher($container) { $dispatcher = new ContainerAwareEventDispatcher($container); $dispatcher->addListener('hook_civicrm_post::Activity', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\SequenceListener', 'onCaseChange_static')); $dispatcher->addListener('DAO::post-insert', array('\\CRM_Core_BAO_RecurringEntity', 'triggerInsert')); $dispatcher->addListener('DAO::post-update', array('\\CRM_Core_BAO_RecurringEntity', 'triggerUpdate')); $dispatcher->addListener('DAO::post-delete', array('\\CRM_Core_BAO_RecurringEntity', 'triggerDelete')); $dispatcher->addListener('hook_civicrm_unhandled_exception', array('CRM_Core_LegacyErrorHandler', 'handleException')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Activity_ActionMapping', 'onRegisterActionMappings')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Contact_ActionMapping', 'onRegisterActionMappings')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Contribute_ActionMapping_ByType', 'onRegisterActionMappings')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Event_ActionMapping', 'onRegisterActionMappings')); $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, array('CRM_Member_ActionMapping', 'onRegisterActionMappings')); return $dispatcher; }
public function persistIdCard(FormInterface $form, $data) { $event = new FormEvent($form, $data); $this->dispatcher->dispatch(ValidationEvents::VALIDATION_ID_CARD_PERSIST, $event); }
public function testPreEventWithSoftDeleteBehavior() { $that = $this; $order = array(); EventDispatcherProxy::setDispatcherGetter(function () use($that, &$order) { $c = $that->getContainer(); $d = new ContainerAwareEventDispatcher($c); $d->addListener('model.delete.pre', function ($e) use($that, &$order) { $order[] = 'model.delete.pre'; }); $d->addListener('delete.pre', function ($e) use($that, &$order) { $order[] = 'delete.pre'; }); $d->addListener('query.delete.pre', function ($e) use($that, &$order) { $order[] = 'query.delete.pre'; }); return $d; }); $m = new SoftdeleteTable(); $m->save(); $m->delete(); $that->assertContains('model.delete.pre', $order, 'Delete model event'); $that->assertContains('delete.pre', $order, 'Model global delete event'); $order = array(); BaseSoftdeleteTableQuery::create()->filterById(1)->delete(); $that->assertContains('delete.pre', $order, 'Query global delete event'); $that->assertContains('query.delete.pre', $order, 'Query delete event'); }
/** * Initialise Zikula. * * Carries out a number of initialisation tasks to get Zikula up and * running. * * @param integer $stage Stage to load. * * @return boolean True initialisation successful false otherwise. */ public function onInit(GetResponseEvent $event) { if ($event->getRequestType() === HttpKernelInterface::SUB_REQUEST) { return; } $this->dispatcher = $event->getDispatcher(); $this->stage = $stage = self::STAGE_ALL; $coreInitEvent = new GenericEvent($this); $coreInitEvent['request'] = $event->getRequest(); // store the load stages in a global so other API's can check whats loaded $this->dispatcher->dispatch(CoreEvents::PREINIT, new GenericEvent($this)); // // Initialise and load configuration // if ($stage & self::STAGE_CONFIG) { // // error reporting // if (!\System::isInstalling()) { // // this is here because it depends on the config.php loading. // $event = new GenericEvent(null, array('stage' => $stage)); // $this->dispatcher->dispatch(CoreEvents::ERRORREPORTING, $event); // } // // // initialise custom event listeners from config.php settings // $coreInitEvent->setArgument('stage', self::STAGE_CONFIG); // $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); // } // // Check that Zikula is installed before continuing // if (\System::getVar('installed') == 0 && !\System::isInstalling()) { // $response = new RedirectResponse(\System::getBaseUrl().'install.php?notinstalled'); // $response->send(); // \System::shutdown(); // } // if ($stage & self::STAGE_DB) { // try { // $dbEvent = new GenericEvent(); // $this->dispatcher->dispatch('doctrine.init_connection', $dbEvent); // $dbEvent = new GenericEvent($this, array('stage' => self::STAGE_DB)); // $this->dispatcher->dispatch(CoreEvents::INIT, $dbEvent); // } catch (\PDOException $e) { // if (!\System::isInstalling()) { // header('HTTP/1.1 503 Service Unavailable'); // require_once \System::getSystemErrorTemplate('dbconnectionerror.tpl'); // \System::shutDown(); // } else { // return false; // } // } // } if ($stage & self::STAGE_TABLES) { // Initialise dbtables \ModUtil::initCoreVars(); if (!\System::isInstalling()) { \ModUtil::registerAutoloaders(); } $coreInitEvent->setArgument('stage', self::STAGE_TABLES); $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); } // // if ($stage & self::STAGE_SESSIONS) { //// \SessionUtil::requireSession(); // $coreInitEvent->setArgument('stage', self::STAGE_SESSIONS); // $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); // } // // // Have to load in this order specifically since we cant setup the languages until we've decoded the URL if required (drak) // // start block // if ($stage & self::STAGE_LANGS) { //// $lang = \ZLanguage::getInstance(); // } // // if ($stage & self::STAGE_DECODEURLS) { //// \System::queryStringDecode(); // $coreInitEvent->setArgument('stage', self::STAGE_DECODEURLS); // $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); // } // // if ($stage & self::STAGE_LANGS) { //// $lang->setup(); // $coreInitEvent->setArgument('stage', self::STAGE_LANGS); // $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); // } // // end block // // if ($stage & self::STAGE_MODS) { //// \ModUtil::load('SecurityCenter'); // // $coreInitEvent->setArgument('stage', self::STAGE_MODS); // $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); // } if ($stage & self::STAGE_THEME) { // register default page vars \PageUtil::registerVar('title'); \PageUtil::setVar('title', \System::getVar('defaultpagetitle')); \PageUtil::registerVar('keywords', true); \PageUtil::registerVar('stylesheet', true); \PageUtil::registerVar('javascript', true); \PageUtil::registerVar('jsgettext', true); \PageUtil::registerVar('body', true); \PageUtil::registerVar('header', true); \PageUtil::registerVar('footer', true); // $theme = \Zikula_View_Theme::getInstance(); // set some defaults // Metadata for SEO // $this->container['zikula_view.metatags']['description'] = \System::getVar('defaultmetadescription'); // $this->container['zikula_view.metatags']['keywords'] = \System::getVar('metakeywords'); $coreInitEvent->setArgument('stage', self::STAGE_THEME); $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent); } // check the users status, if not 1 then log him out // if (\UserUtil::isLoggedIn()) { // $userstatus = \UserUtil::getVar('activated'); // if ($userstatus != UsersConstant::ACTIVATED_ACTIVE) { // \UserUtil::logout(); // // TODO - When getting logged out this way, the existing session is destroyed and // // then a new one is created on the reentry into index.php. The message // // set by the registerStatus call below gets lost. // \LogUtil::registerStatus(__('You have been logged out.')); // $response = new RedirectResponse(\ModUtil::url('Users', 'user', 'login')); // $response->send(); // exit; // } // } // if (($stage & self::STAGE_POST) && ($this->stage & ~self::STAGE_POST)) { // $this->dispatcher->dispatch(CoreEvents::POSTINIT, new GenericEvent($this, array('stages' => $stage))); // } // // $this->dispatcher->dispatch('frontcontroller.predispatch', new GenericEvent()); }
/** * @param ContainerInterface $container * @param Stopwatch $stopwatch * @param LoggerInterface $logger */ public function __construct(ContainerInterface $container, Stopwatch $stopwatch, LoggerInterface $logger) { parent::__construct($container); $this->stopwatch = $stopwatch; $this->logger = $logger; }
public function testRemoveBeforeDispatch() { $service = $this->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service'); $container = new Container(); $container->set('service.listener', $service); $dispatcher = new ContainerAwareEventDispatcher($container); $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent')); $dispatcher->removeListener('onEvent', array($container->get('service.listener'), 'onEvent')); $this->assertFalse($dispatcher->hasListeners('onEvent')); }
/** * @param $eventName * @param array $keys * * @return array */ protected function dispatchIntegrationKeyEvent($eventName, $keys = array()) { /** @var PluginIntegrationKeyEvent $event */ $event = $this->dispatcher->dispatch($eventName, new PluginIntegrationKeyEvent($this, $keys)); return $event->getKeys(); }
public function __construct(ContainerInterface $container, IInvoker $invoker) { parent::__construct($container); $this->invoker = $invoker; }
/** * Dispatches an event to all registered listeners. * * Wrapper for Symfony\Component\EventDispatcher\EventDispatcher::dispatch method. * * @param string $eventName The name of the event to dispatch. The name of the event is the name of the method that is invoked on listeners. * @param Event $event The event to pass to the event handlers/listeners. If not supplied, an empty Event instance is created. * * @return Event */ public function notify($eventName, Event $event) { return parent::dispatch($eventName, $event); }
/** * Dispatch event. * * @param string $name * @param Symfony\Component\EventDispatcher\Event $event * * @return Zikula_Event */ public function dispatch($name, Event $event = null) { $dispatcher = func_num_args() === 3 ? func_get_arg(2) : null; return parent::dispatch($name, $event, $dispatcher); }
/** * Flush handlers. * * Clears all handlers. * * @return void */ public function flushHandlers() { foreach ($this->dispatcher->getListeners() as $eventName => $listener) { $this->dispatcher->removeListener($eventName, $listener); } }
/** * {@inheritDoc} */ protected function lazyLoad($eventName) { $e = $this->stopwatch->start($eventName . '.loading', 'event_listener_loading'); parent::lazyLoad($eventName); $e->stop(); }
/** * Reboot. * * Shutdown the system flushing all event handlers, services and service arguments. * * @return void */ public function reboot() { $event = new GenericEvent($this); $this->dispatcher->dispatch('shutdown', $event); // flush handlers foreach ($this->dispatcher->getListeners() as $eventName => $listener) { $this->dispatcher->removeListener($eventName, $listener); } // flush all services $services = $this->container->getServiceIds(); rsort($services); foreach ($services as $id) { if (!in_array($id, array('zikula', 'service_container', 'event_dispatcher'))) { $this->container->removeDefinition($id); } } // flush arguments. $this->container->setArguments(array()); $this->attachedHandlers = array(); $this->stage = 0; $this->bootime = microtime(true); }