/** * 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()); }
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([]); }
/** * @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)); } }
/** * {@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; }
/** * Dispatches an event and returns its associated event object. The event object * is created according to the short event class name parameter, which must match * an event class located in the core event directory, without the first path * segments and the "Event" suffix. * * @param string $eventName Name of the event * @param string $shortEventClassName Short name of the event class * @param array $eventArgs Parameters to be passed to the event object constructor * * @return \Symfony\Component\EventDispatcher\Event * * @throws MissingEventClassException if no event class matches the short class name * @throws MandatoryEventException if the event is mandatory but have no listener observing it * @throws NotPopulatedEventException if the event is supposed to be populated with data but it isn't */ public function dispatch($eventName, $shortEventClassName, array $eventArgs = array()) { $className = class_exists($shortEventClassName) ? $shortEventClassName : "Claroline\\CoreBundle\\Event\\{$shortEventClassName}Event"; if (!class_exists($className)) { throw new MissingEventClassException("No event class matches the short name '{$shortEventClassName}' (looked for '{$className})"); } $rEvent = new \ReflectionClass($className); $event = $rEvent->newInstanceArgs($eventArgs); if ($event instanceof MandatoryEventInterface && !$this->eventDispatcher->hasListeners($eventName)) { throw new MandatoryEventException("No listener is attached to the '{$eventName}' event"); } $this->eventDispatcher->dispatch($eventName, $event); if ($event instanceof DataConveyorEventInterface && !$event->isPopulated()) { throw new NotPopulatedEventException("Event object for '{$eventName}' was not populated as expected"); } return $event; }
/** * 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; }
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)); }
public function testEventReceivesTheDispatcherInstanceAsArgument() { $listener = new TestWithDispatcher(); $this->dispatcher->addListener('test', array($listener, 'foo')); $this->assertNull($listener->name); $this->assertNull($listener->dispatcher); $this->dispatcher->dispatch('test'); $this->assertEquals('test', $listener->name); $this->assertSame($this->dispatcher, $listener->dispatcher); }
/** * @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); }
/** * 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(); }
/** * {@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); }
/** * @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)); } }
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); } }
/** * @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); }
/** * 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 notifyConsumers($routingKey, AMQPMessageEvent $event) { $this->dispatcher->dispatch($routingKey, $event); }
/** * Render an exception as an HTTP response and send it. * * @param \Exception $e * @return void */ protected function renderHttpResponse($e) { //dev下面需要render信息 if ($this->app->container->getEnvironment() == 'prod') { $controller = new \Controller($this->app); $e = $controller->twigInit()->render(\Config::get('view::error_page')); } else { if (!is_array($e)) { $trace = debug_backtrace(); $error['message'] = $e; $error['file'] = $trace[0]['file']; $error['line'] = $trace[0]['line']; ob_start(); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $e['trace'] = ob_get_clean(); $e = $error; } } \EventDispatcher::dispatch(KernalEvent::EXCEPTION, new ExceptionEvent($e)); }
/** * 处理响应请求 * */ public function handleHttp() { $response = $this->container->getResponse(); $request = $this->container->getRequest(); \EventDispatcher::dispatch(KernalEvent::RESPONSE, new HttpEvent($request, $response)); }
/** * do the controller * * @param routing config * @return string */ public function controller($config) { list($group, $subGroup, $controller, $action) = explode(':', $config['controller']); $className = 'src\\' . $group . '\\Controller\\' . $subGroup . '\\' . $controller . 'Controller'; $action = $action . 'Action'; $this->route->setAction($action); $this->route->setParameters(isset($config['parameters']) ? $config['parameters'] : array()); $response = $this->container->doAction($className, $action, isset($config['parameters']) ? $config['parameters'] : array(), $this->request); \EventDispatcher::dispatch('kernal.response', new HttpEvent($response)); }
/** * 设置request * */ public function setRequest(\Request $request) { \EventDispatcher::dispatch(KernalEvent::REQUEST, new HttpEvent($request)); $this->request = $request; }
public function onException(\Event $event) { $response = new \Response($event->getTrace(), 500); \EventDispatcher::dispatch(KernalEvent::RESPONSE, new HttpEvent(null, $response)); }