public function testDispatch()
 {
     $this->dispatcher->listen(EventDispatcherInterface::EVENT_REQUEST_SUCCESS, [$this, 'handler']);
     $this->assertFalse($this->hasBeenCalled);
     $this->dispatcher->dispatch(EventDispatcherInterface::EVENT_REQUEST_SUCCESS, new Event());
     $this->assertTrue($this->hasBeenCalled);
 }
 public function emit($name, $event = null)
 {
     if ($event !== null && !$event instanceof Event) {
         $event = new GenericEvent($name, $event);
     }
     $this->dispatcher->dispatch($name, $event);
 }
 public function sendAction(Request $request)
 {
     $message = $this->messageBuilder->getMessage($request->request->all());
     $this->eventDispatcher->dispatch('slack.message_received', new MessageEvent($message));
     $this->entityManager->flush();
     return new JsonResponse([]);
 }
 /**
  * invoked after purchasing the guides. sends the email
  * @param  PurchaseInfo $purchaseInfo []
  *
  * @return null
  */
 public function sendMail($purchaseInfo)
 {
     $event = new PurchaseEvent($this->messageBuilder, $purchaseInfo);
     // $this->get('event_dispatcher')->dispatch('buggl.approve_eguide',$event);
     $this->dispatcher->dispatch('buggl.purchase', $event);
     $this->dispatcher->dispatch('buggl.notify_buyer', $event->buildMessageForBuyer());
 }
 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Check if the event has a nodeTranslation, if not this method can be skipped
     if (!$request->attributes->has('_nodeTranslation')) {
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     if (!$nodeTranslation instanceof NodeTranslation) {
         $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslation);
         $request->attributes->set('_nodeTranslation', $nodeTranslation);
     }
     $entity = $nodeTranslation->getRef($this->em);
     // If the entity is an instance of the SlugActionInterface, change the controller
     if ($entity instanceof SlugActionInterface) {
         $request->attributes->set('_entity', $entity);
         // Do security check by firing an event that gets handled by the SlugSecurityListener
         $securityEvent = new SlugSecurityEvent();
         $securityEvent->setNode($nodeTranslation->getNode())->setEntity($entity)->setRequest($request)->setNodeTranslation($nodeTranslation);
         $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);
         // Set the right controller
         $request->attributes->set('_controller', $entity->getControllerAction());
         $event->setController($this->resolver->getController($request));
     }
 }
 public function testEventCanBeDispatched()
 {
     $eventName = 'foo';
     $dispatcher = new EventDispatcher();
     $dispatcher->registerEvent($eventName);
     $data = ['foo', 'bar'];
     $dispatcher->dispatchEvent($eventName, $data);
 }
 /**
  * @covers \Heystack\Core\EventDispatcher::dispatch
  */
 public function testDoesDispatchWhenEnabled()
 {
     $fired = false;
     $e = new EventDispatcher();
     $e->addListener('test', function () use(&$fired) {
         $fired = true;
     });
     $e->dispatch('test');
     $this->assertTrue($fired);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(DatagridInterface $datagrid, MassActionInterface $massAction)
 {
     // dispatch pre handler event
     $massActionEvent = new MassActionEvent($datagrid, $massAction, array());
     $this->eventDispatcher->dispatch(MassActionEvents::MASS_EDIT_PRE_HANDLER, $massActionEvent);
     $datasource = $datagrid->getDatasource();
     $datasource->setHydrator($this->hydrator);
     // hydrator uses index by id
     $objectIds = $datasource->getResults();
     // dispatch post handler event
     $massActionEvent = new MassActionEvent($datagrid, $massAction, array());
     $this->eventDispatcher->dispatch(MassActionEvents::MASS_EDIT_POST_HANDLER, $massActionEvent);
     return $objectIds;
 }
 public static function inst()
 {
     if (is_null(EventDispatcher::$instance)) {
         EventDispatcher::$instance = new Dispatcher();
     }
     return EventDispatcher::$instance;
 }
Example #10
0
 /**
  * Load all persistent events handlers into EventManager.
  *
  * This loads persistent events registered by modules and module plugins.
  *
  * @internal
  *
  * @return void
  */
 public static function loadPersistentEvents()
 {
     $handlerGroup = ModUtil::getVar(self::HANDLERS);
     if (!$handlerGroup) {
         return;
     }
     foreach ($handlerGroup as $module => $handlers) {
         if (!$handlers) {
             continue;
         }
         foreach ($handlers as $handler) {
             if (ModUtil::available($module)) {
                 try {
                     if (isset($handler['classname'])) {
                         self::attachEventHandler($handler['classname']);
                     } else {
                         self::$dispatcher->addListener($handler['eventname'], $handler['callable'], $handler['weight']);
                     }
                 } catch (InvalidArgumentException $e) {
                     LogUtil::log(sprintf("Event handler could not be attached because %s", $e->getMessage()), Zikula_AbstractErrorHandler::ERR);
                 }
             }
         }
     }
 }
Example #11
0
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new EventDispatcher();
     }
     return self::$_instance;
 }
 public function onKernalResponse(\Event $event)
 {
     $response = $event->getResponse();
     if ($response instanceof \Response || $response instanceof \RedirectResponse || $response instanceof \JsonResponse) {
         $response->send();
     }
     \EventDispatcher::dispatch(KernalEvent::HTTPFINISH, new HttpEvent($event->getRequest(), $response));
 }
Example #13
0
 /**
  * Runs a kernel target
  *
  * @param KernelHandleWebInterface $target
  */
 public function handle(KernelHandleInterface $target, Request $request)
 {
     $event = new KernelHandleEvent($target);
     $this->dispatcher->dispatch(KernelHandleEvent::PRE_RUN, $event);
     $response = $target->run($request);
     $this->dispatcher->dispatch(KernelHandleEvent::POST_RUN, $event);
     return $response;
 }
Example #14
0
 /**
  * For initial settings purposes
  */
 protected function initialize($options)
 {
     $this->config = ConfigManager::bind();
     $this->event_dispatcher = EventDispatcher::bind();
     $this->primary_url_target = $options['url_target'];
     $this->instance_identifier = $options['instance_identifier'];
     $this->stop_condition_adquired = FALSE;
     $this->event_dispatcher->connect('context.webbot_injected', array($this, 'ContextWebbotInjectedEventHandler'));
     //$this->event_dispatcher->connect('webbot.stop_condition_adquired', array($this, 'WebbotStopConditionAdquiredEventHandler'));
 }
Example #15
0
 public function __construct(AbstractServer &$server, $socket, $timeout)
 {
     parent::__construct();
     $this->_uid = null;
     $this->_timeout = $timeout;
     $this->_last_time = time();
     socket_getpeername($socket, $this->_address, $this->_port);
     socket_set_nonblock($socket);
     $this->_socket =& $socket;
     $this->_server =& $server;
 }
 /**
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     //check if the event has anything to do with nodeTranslations, if not this method can be skipped
     if (!$request->attributes->has('_nodeTranslation')) {
         return;
     }
     $nodeTranslation = $request->attributes->get('_nodeTranslation');
     $entity = $nodeTranslation->getRef($this->em);
     //if the entity is an instance of the SlugControllerActionInterface, change the controller
     if ($entity instanceof SlugActionInterface) {
         $request->attributes->set('_entity', $entity);
         //do security check by firing an event that gets handled by the SlugSecurityListener
         $securityEvent = new SlugSecurityEvent();
         $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);
         //set the right controller
         $request->attributes->set('_controller', $entity->getControllerAction());
         $event->setController($this->resolver->getController($request));
     }
 }
Example #17
0
 public function __construct($port, $timeout, $max_connection)
 {
     parent::__construct();
     $this->_address = null;
     $this->_port = $port;
     $this->_timeout = $timeout;
     $this->_max_connection = $max_connection;
     $this->_last_time = time();
     $this->_socket = null;
     $this->_clients = array();
 }
 /**
  * {@inheritdoc}
  */
 public function handle(DatagridInterface $datagrid, MassActionInterface $massAction)
 {
     // dispatch pre handler event
     $massActionEvent = new MassActionEvent($datagrid, $massAction, []);
     $this->eventDispatcher->dispatch(MassActionEvents::MASS_DELETE_PRE_HANDLER, $massActionEvent);
     $datasource = $datagrid->getDatasource();
     $datasource->setHydrator($this->hydrator);
     // hydrator uses index by id
     $objectIds = $datasource->getResults();
     try {
         $countRemoved = $datasource->getMassActionRepository()->deleteFromIds($objectIds);
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         return new MassActionResponse(false, $this->translator->trans($errorMessage));
     }
     // dispatch post handler event
     $massActionEvent = new MassActionEvent($datagrid, $massAction, $objectIds);
     $this->eventDispatcher->dispatch(MassActionEvents::MASS_DELETE_POST_HANDLER, $massActionEvent);
     return $this->getResponse($massAction, $countRemoved);
 }
Example #19
0
 /**
  * init appliaction
  *
  */
 public function init($path)
 {
     $this->initSelf();
     $request = \Request::createFromGlobals();
     $this->registerServices();
     \EventDispatcher::dispatch('kernal.init');
     $this->container = $this->singleton('container');
     $this->container->setAppPath($path);
     $this->router = new Router($this->container, $request);
     $this->router->match();
 }
Example #20
0
 /**
  * Unleashed the routine for loggin the exception
  * 
  */
 private function notifyException()
 {
     $parameters = array("type" => get_class($this), "message" => $this->getMessage(), "file" => $this->file, "line" => $this->line);
     if ($this->getPrevious() !== NULL) {
         $parameters["inner_type"] = get_class($this->getPrevious());
         $parameters["inner_message"] = $this->getPrevious()->getMessage();
         $parameters["inner_file"] = $this->getPrevious()->getFile();
         $parameters["inner_line"] = $this->getPrevious()->getLine();
     }
     $dispatcher = EventDispatcher::bind();
     // notifying exception
     $dispatcher->notify(new Event($this, 'application.log_exception', $parameters));
 }
 public function process(ValidatorInterface $validator, Request $request)
 {
     $eventName = $request->headers->get('X-Webhook-Name');
     if (!$validator->isEventSupported($eventName)) {
         throw new Exception(sprintf('"%s" event is not supported', $eventName));
     }
     $mime = $request->headers->get('Content-Type');
     $mime = explode('; ', $mime)[0];
     $mime = explode('/', $mime)[1];
     if (!in_array($mime, ['json', 'xml'])) {
         throw new Exception('Invalid webhook payload format');
     }
     $body = $request->getContent();
     if (!$body) {
         throw new Exception('Empty payload');
     }
     if ($mime == 'json') {
         $body = @json_decode($body);
     } else {
         $body = @simplexml_load_string($body);
     }
     if (!$body) {
         throw new Exception('Malformed payload');
     }
     $eventName = preg_replace('#[^a-z\\.]#si', '', $eventName);
     $className = explode('.', $eventName, 2);
     $className = array_map('ucfirst', $className);
     $className[] = 'Event';
     $fqcn = sprintf('DreamCommerce\\ShopAppstoreBundle\\Event\\Webhook\\%s', implode('', $className));
     if (!class_exists($fqcn)) {
         throw new Exception(sprintf('Class %s not found', $fqcn));
     }
     /**
      * @var $class EventAbstract
      */
     $class = new $fqcn($body, $this->shop, $this->application);
     $this->dispatcher->dispatch(sprintf('dream_commerce_shop_appstore.webhook.%s', $eventName), $class);
 }
 private function tryToProcessRDFTestCase($jsonTestCaseFileHandler)
 {
     // For some reason there are some random failures where
     // the instance hasn't reset the cache in time to fetch the
     // property definition which only happens for the SPARQLStore
     // This should not be necessary because the resetcache event
     // is triggered`
     $this->eventDispatcher->dispatch('exporter.reset');
     $this->eventDispatcher->dispatch('query.comparator.reset');
     $this->rdfTestCaseProcessor->setDebugMode($jsonTestCaseFileHandler->getDebugMode());
     foreach ($jsonTestCaseFileHandler->findTestCasesFor('rdf-testcases') as $case) {
         $this->rdfTestCaseProcessor->process($case);
     }
 }
Example #23
0
 public function onEventDispatcherInit(\Event $event)
 {
     $listeners = [['eventName' => 'kernal.response', 'listener' => 'core\\Group\\Listeners\\KernalResponseListener', 'priority' => 0]];
     $listeners = array_merge(\Config::get('listener::services'), $listeners);
     foreach ($listeners as $listener) {
         if (!class_exists($listener['listener'])) {
             throw new NotFoundException("Class " . $listener['listener'] . " not found !");
         }
         $lis = new $listener['listener']();
         if (!$lis instanceof Listener) {
             throw new \RuntimeException("Class " . $listener['listener'] . " must instanceof Listener !");
         }
         \EventDispatcher::addListener($listener['eventName'], $lis, $listener['priority']);
     }
 }
 public function onKernalInit(\Event $event)
 {
     $listeners = [['eventName' => KernalEvent::REQUEST, 'listener' => 'Group\\Listeners\\KernalRequestListener', 'priority' => 0], ['eventName' => KernalEvent::RESPONSE, 'listener' => 'Group\\Listeners\\KernalResponseListener', 'priority' => 0], ['eventName' => KernalEvent::EXCEPTION, 'listener' => 'Group\\Listeners\\ExceptionListener', 'priority' => 0], ['eventName' => KernalEvent::NOTFOUND, 'listener' => 'Group\\Listeners\\NotFoundListener', 'priority' => 0]];
     $listeners = array_merge(\Config::get('listener::services'), $listeners);
     foreach ($listeners as $listener) {
         if (!class_exists($listener['listener'])) {
             throw new NotFoundException("Class " . $listener['listener'] . " not found !");
         }
         $lis = new $listener['listener']();
         if (!$lis instanceof Listener) {
             throw new \RuntimeException("Class " . $listener['listener'] . " must instanceof Listener !");
         }
         \EventDispatcher::addListener($listener['eventName'], $lis, $listener['priority']);
     }
 }
Example #25
0
 /**
  * @param PackageEvent $event
  * @throws \Exception
  */
 public function postInstall(PackageEvent $event)
 {
     // Get the package object for the current operation.
     $operation = $event->getOperation();
     /** @var PackageInterface $package */
     $package = $this->getPackageFromOperation($operation);
     $package_name = $package->getName();
     if (!isset($this->patches[$package_name])) {
         if ($this->io->isVerbose()) {
             $this->io->write('<info>No patches found for ' . $package_name . '.</info>');
         }
         return;
     }
     $this->io->write('  - Applying patches for <info>' . $package_name . '</info>');
     // Get the install path from the package object.
     $manager = $event->getComposer()->getInstallationManager();
     $install_path = $manager->getInstaller($package->getType())->getInstallPath($package);
     // Set up a downloader.
     $downloader = new RemoteFilesystem($this->io, $this->composer->getConfig());
     // Track applied patches in the package info in installed.json
     $localRepository = $this->composer->getRepositoryManager()->getLocalRepository();
     $localPackage = $localRepository->findPackage($package_name, $package->getVersion());
     $extra = $localPackage->getExtra();
     $extra['patches_applied'] = array();
     foreach ($this->patches[$package_name] as $patch) {
         $url = $patch['url'];
         $description = $patch['description'];
         $sha1 = NULL;
         if (!empty($patch['sha1'])) {
             $sha1 = $patch['sha1'];
         }
         $this->io->write('    <info>' . $url . '</info> (<comment>' . $description . '</comment>)');
         try {
             $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $url, $description, $sha1));
             $this->getAndApplyPatch($downloader, $install_path, $url, $sha1);
             $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::POST_PATCH_APPLY, $package, $url, $description, $sha1));
             $extra['patches_applied'][$description] = $url;
         } catch (\Exception $e) {
             $this->io->write('   <error>Could not apply patch! Skipping.</error>');
         }
     }
     $localPackage->setExtra($extra);
     $this->io->write('');
     $this->writePatchReport($this->patches[$package_name], $install_path);
 }
Example #26
0
 /**
  * match the uri
  *
  */
 public function match()
 {
     $requestUri = $this->route->getUri();
     $routing = $this->getRouting();
     if (isset($routing[$requestUri])) {
         $this->controller($routing[$requestUri]);
         return;
     }
     foreach ($routing as $routeKey => $route) {
         preg_match_all('/{(.*?)}/', $routeKey, $matches);
         $config = "";
         if ($matches[0]) {
             $config = $this->pregUrl($matches, $routeKey, $routing);
         }
         if ($config) {
             $this->controller($config);
             return;
         }
     }
     \EventDispatcher::dispatch(KernalEvent::NOTFOUND, new HttpEvent($this->container->getRequest()));
 }
 /**
  * Called at the "kernel.request" event
  *
  * Call the LocaleGuesserManager to guess the locale
  * by the activated guessers
  *
  * Sets the identified locale as default locale to the request
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if ($this->excludedPattern && preg_match(sprintf('#%s#', $this->excludedPattern), $request->getPathInfo())) {
         return;
     }
     $request->setDefaultLocale($this->defaultLocale);
     $manager = $this->guesserManager;
     $locale = $manager->runLocaleGuessing($request);
     if ($locale && $this->bestLocaleMatcher) {
         $locale = $this->bestLocaleMatcher->match($locale);
     }
     if ($locale) {
         $this->logEvent('Setting [ %s ] as locale for the (Sub-)Request', $locale);
         $request->setLocale($locale);
         $request->attributes->set('_locale', $locale);
         if (($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST || $request->isXmlHttpRequest()) && ($manager->getGuesser('session') || $manager->getGuesser('cookie'))) {
             $localeSwitchEvent = new FilterLocaleSwitchEvent($request, $locale);
             $this->dispatcher->dispatch(LocaleBundleEvents::onLocaleChange, $localeSwitchEvent);
         }
     }
 }
 /**
  * Start repair a building
  *
  * @param Building $building
  * @param $type
  * @return int
  */
 public function repair(Building $building, $type)
 {
     $amount = $this->buildingRepairPrice->countPrice($building, $type);
     if (!$this->gamerHasEnoughCash->isSatisfiedBy($building->getGamer(), $amount)) {
         throw new NotEnoughCashException();
     }
     if ($this->buildingRepairRepository->countActiveBuildings($building) > 0) {
         throw new BuildingAlreadyRepairing();
     }
     $duration = $this->buildingRepairPrice->getTimeConstant($type) * (100 - $building->getCurrentCondition());
     $buildingRepair = new BuildingRepair();
     $buildingRepair->setBuilding($building);
     $buildingRepair->setStatus(BuildingRepair::STATUS_ACTIVE);
     $buildingRepair->setType($type);
     $buildingRepair->setValidDuration($duration);
     $buildingRepair->setStartedCondition($building->getCurrentCondition());
     $this->buildingRepairRepository->save($buildingRepair);
     $building->setStatus(Building::INACTIVE);
     $this->buildingRepository->update();
     $this->reduceCash->reduce($building->getGamer(), $amount);
     $event = new BuildingRepairStarted($building);
     $this->eventDispatcher->dispatch($event::NAME, $event);
 }
 public function hasListeners($eventName)
 {
     return $this->eventDispatcher->hasListeners($eventName);
 }
Example #30
0
 /**
  * {@inheritDoc}
  */
 public function removeListener(EventListener $listener)
 {
     $this->eventDispatcher->removeListener($listener);
     return $this;
 }