Как сделать, чтобы
commandBus вызвался после цикла один раз, а не при каждой интерации?
foreach ($dCampaigns as $dCampaign) {
$search = $dCampaign->getSearch();
$groupId = $this->userRepository->findById($dCampaign->getUserId())->getGroupId();
$contactCollection = $this->contactRepository->findByTagIds(false, false, $search, $groupId);
if (null !== $contactCollection) {
for ($i = 0; $i < count($contactCollection); $i++) {
if (null === $contactCollection[$i]->getEmail()) continue;
$command->subject = $dCampaign->getSubject();
$command->body = $dCampaign->getContent();
$command->contact = $contactCollection[$i];
$command->userEmail = $dCampaign->getSenderEmail();
$command->campaignId = $dCampaign->getIdValue();
$command->replyToEmail = $dCampaign->getReplyToEmail();
$this->commandBus->handle($command);
}
}
}