dispatch example

public function handle(EntityIndexingMessage $message): void
    {
        $ids = $message->getData();

        if (empty($ids)) {
            return;
        }

        $this->distinguishableNameGenerator->generateDistinguishablePaymentNames($message->getContext());

        $this->eventDispatcher->dispatch(new PaymentMethodIndexerEvent($ids$message->getContext()$message->getSkip()));
    }

    public function getTotal(): int
    {
        return $this->iteratorFactory->createIterator($this->paymentMethodRepository->getDefinition())->fetchCount();
    }

    public function getDecorated(): EntityIndexer
    {
        throw new DecorationPatternException(static::class);
    }
}
$this->contextPersister->save(
            $context->getToken(),
            $parameters,
            $context->getSalesChannel()->getId(),
            $customer && empty($context->getPermissions()) ? $customer->getId() : null
        );

        // Language was switched - Check new Domain         $changeUrl = $this->checkNewDomain($parameters$context);

        $event = new SalesChannelContextSwitchEvent($context$data);
        $this->eventDispatcher->dispatch($event);

        return new ContextTokenResponse($context->getToken()$changeUrl);
    }

    /** * @param array<mixed> $parameters */
    private function checkNewDomain(array $parameters, SalesChannelContext $context): ?string
    {
        if (
            !isset($parameters[self::LANGUAGE_ID])
            
private readonly SystemConfigService $systemConfigService,
        private readonly EventDispatcherInterface $eventDispatcher,
        private readonly AbstractProductCloseoutFilterFactory $productCloseoutFilterFactory
    ) {
    }

    public function load(Request $request, SalesChannelContext $context): GuestWishlistPagelet
    {
        $page = new GuestWishlistPagelet();

        $criteria = $this->createCriteria($request$context);
        $this->eventDispatcher->dispatch(new GuestWishListPageletProductCriteriaEvent($criteria$context$request));

        if (empty($criteria->getIds())) {
            $response = new ProductListResponse(new EntitySearchResult(
                'wishlist',
                0,
                new ProductCollection(),
                null,
                $criteria,
                $context->getContext()
            ));
        } else {
            
case ProductExportEntity::FILE_FORMAT_CSV:
                $contentType = 'text/csv';

                break;
            case ProductExportEntity::FILE_FORMAT_XML:
                $contentType = 'text/xml';

                break;
        }

        $event = new ProductExportContentTypeEvent($fileFormat$contentType);
        $this->eventDispatcher->dispatch($event);

        return $event->getContentType();
    }

    private function logException(
        Context $context,
        \Exception $exception,
        Level $logLevel = Level::Error
    ): void {
        $loggingEvent = new ProductExportLoggingEvent(
            $context,
            
$page->setDeepLinkCode($request->get('deepLinkCode'));

        $firstOrder = $page->getOrders()->getEntities()->first();
        $orderCustomerId = $firstOrder?->getOrderCustomer()?->getCustomer()?->getId();
        if ($request->get('deepLinkCode') && $orderCustomerId !== null) {
            $this->accountService->loginById(
                $orderCustomerId,
                $salesChannelContext
            );
        }

        $this->eventDispatcher->dispatch(
            new AccountOrderPageLoadedEvent($page$salesChannelContext$request)
        );

        return $page;
    }

    /** * @throws CustomerNotLoggedInException * @throws GuestNotAuthenticatedException * @throws WrongGuestCredentialsException * * @return EntitySearchResult<OrderCollection> */


    return $return;
  }

  /** * {@inheritdoc} */
  public function getConfigCollectionInfo() {
    if (!isset($this->configCollectionInfo)) {
      $this->configCollectionInfo = new ConfigCollectionInfo();
      $this->eventDispatcher->dispatch($this->configCollectionInfo, ConfigEvents::COLLECTION_INFO);
    }
    return $this->configCollectionInfo;
  }

  /** * Calls an entity's onDependencyRemoval() method. * * A helper method to call onDependencyRemoval() with the correct list of * affected entities. This list should only contain dependencies on the * entity. Configuration and content entity dependencies will be converted * into entity objects. * * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity * The entity to call onDependencyRemoval() on. * @param \Drupal\Core\Config\Entity\ConfigEntityInterface[] $dependent_entities * The list of dependent configuration entities. * @param string $type * The type of dependency being checked. Either 'module', 'theme', 'config' * or 'content'. * @param array $names * The specific names to check. If $type equals 'module' or 'theme' then it * should be a list of module names or theme names. In the case of 'config' * or 'content' it should be a list of configuration dependency names. * * @return bool * TRUE if the entity has changed as a result of calling the * onDependencyRemoval() method, FALSE if not. */
$step = \count($message->getData()->getIds());

            if ($input->getOption('no-queue')) {
                $this->indexer->__invoke($message);

                $progressBar->advance($step);

                continue;
            }

            $this->messageBus->dispatch($message);

            $progressBar->advance($step);
        }

        $progressBar->finish();

        if ($input->getOption('no-queue')) {
            $this->aliasHandler->run();
        }

        $event = (string) $stopwatch->stop('es-indexing');

        
public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher)
    {
        $this->voter = $voter;
        $this->eventDispatcher = $eventDispatcher;
    }

    public function vote(TokenInterface $token, mixed $subject, array $attributes): int
    {
        $result = $this->voter->vote($token$subject$attributes);

        $this->eventDispatcher->dispatch(new VoteEvent($this->voter, $subject$attributes$result), 'debug.security.authorization.vote');

        return $result;
    }

    public function getDecoratedVoter(): VoterInterface
    {
        return $this->voter;
    }

    public function supportsAttribute(string $attribute): bool
    {
        
private function loadProduct(Criteria $criteria, Context $context, string $id): ?ProductEntity
    {
        $context->setConsiderInheritance(true);

        $event = new BeforeLoadStorableFlowDataEvent(
            ProductDefinition::ENTITY_NAME,
            $criteria,
            $context,
        );

        $this->dispatcher->dispatch($event$event->getName());

        /** @var ProductEntity|null $product */
        $product = $this->productRepository->search($criteria$context)->get($id);

        return $product;
    }
}
$criteria->addAssociation('defaultBillingAddress.country');
        $criteria->addAssociation('defaultBillingAddress.countryState');
        $criteria->addAssociation('defaultBillingAddress.salutation');
        $criteria->addAssociation('defaultShippingAddress.country');
        $criteria->addAssociation('defaultShippingAddress.countryState');
        $criteria->addAssociation('defaultShippingAddress.salutation');

        /** @var CustomerEntity $customerEntity */
        $customerEntity = $this->customerRepository->search($criteria$context->getContext())->first();

        if ($customerEntity->getDoubleOptInRegistration()) {
            $this->eventDispatcher->dispatch($this->getDoubleOptInEvent($customerEntity$context$data->get('storefrontUrl')$data->get('redirectTo')));

            // We don't want to leak the hash in store-api             $customerEntity->setHash('');

            return new CustomerResponse($customerEntity);
        }

        $response = new CustomerResponse($customerEntity);

        $newToken = $this->contextPersister->replace($context->getToken()$context);

        
$listener = new ResponseListener('UTF-8');
        $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...));

        $this->kernel = $this->createMock(HttpKernelInterface::class);
    }

    public function testFilterDoesNothingForSubRequests()
    {
        $response = new Response('foo');

        $event = new ResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
        $this->dispatcher->dispatch($event, KernelEvents::RESPONSE);

        $this->assertEquals('', $event->getResponse()->headers->get('content-type'));
    }

    public function testFilterSetsNonDefaultCharsetIfNotOverridden()
    {
        $listener = new ResponseListener('ISO-8859-15');
        $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener->onKernelResponse(...), 1);

        $response = new Response('foo');

        

        }

        if ($message->allow(self::CHILD_COUNT_UPDATER)) {
            $this->childCountUpdater->update(MediaFolderDefinition::ENTITY_NAME, $ids$message->getContext());
        }

        if (!empty($children) && $message->allow(self::TREE_UPDATER)) {
            $this->treeUpdater->batchUpdate($children, MediaFolderDefinition::ENTITY_NAME, $context);
        }

        $this->eventDispatcher->dispatch(new MediaFolderIndexerEvent($ids$message->getContext()$message->getSkip()));
    }

    public function getOptions(): array
    {
        return [
            self::CHILD_COUNT_UPDATER,
            self::TREE_UPDATER,
        ];
    }

    public function getTotal(): int
    {
#[Route(path: '/api/_action/import-export/process', name: 'api.action.import_export.process', methods: ['POST'])]     public function process(Request $request, Context $context): Response
    {
        $logId = strtolower((string) $request->request->get('logId'));

        $importExport = $this->importExportFactory->create($logId, 50, 50);
        $logEntity = $importExport->getLogEntity();

        $message = new ImportExportMessage($context$logEntity->getId()$logEntity->getActivity());

        $this->messageBus->dispatch($message);

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/import-export/file/prepare-download/{fileId}', name: 'api.action.import_export.file.prepare-download', methods: ['POST'])]     public function prepareDownload(string $fileId, Context $context): Response
    {
        $token = $this->downloadService->regenerateToken($context$fileId);

        return new JsonResponse(['accessToken' => $token]);
    }

    

    public function run(array $options = []): void
    {
        $options = array_merge([
            'sleep' => 1000000,
        ]$options);
        $queueNames = $options['queues'] ?? null;

        $this->metadata->set(['queueNames' => $queueNames]);

        $this->eventDispatcher?->dispatch(new WorkerStartedEvent($this));

        if ($queueNames) {
            // if queue names are specified, all receivers must implement the QueueReceiverInterface             foreach ($this->receivers as $transportName => $receiver) {
                if (!$receiver instanceof QueueReceiverInterface) {
                    throw new RuntimeException(sprintf('Receiver for "%s" does not implement "%s".', $transportName, QueueReceiverInterface::class));
                }
            }
        }

        while (!$this->shouldStop) {
            
if ($this->lockSetData) {
            throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
        }

        $this->lockSetData = true;
        $dispatcher = $this->config->getEventDispatcher();

        // Hook to change content of the model data before transformation and mapping children         if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA)) {
            $event = new PreSetDataEvent($this$modelData);
            $dispatcher->dispatch($event, FormEvents::PRE_SET_DATA);
            $modelData = $event->getData();
        }

        // Treat data as strings unless a transformer exists         if (\is_scalar($modelData) && !$this->config->getViewTransformers() && !$this->config->getModelTransformers()) {
            $modelData = (string) $modelData;
        }

        // Synchronize representations - must not change the content!         // Transformation exceptions are not caught on initialization         $normData = $this->modelToNorm($modelData);
        
Home | Imprint | This part of the site doesn't use cookies.