СП
final class CommentService
{
private CommentRepositoryInterface $commentRepository;
private DeferredEventService $eventService;
public function create(string $threadId, string $userId, string $body, ?string $byUserId = null): Comment
{
$this->eventService->pushEvent(new EventBefore());
$comment = new Comment(
UuidHelper::generateTimestampFirstCombUuid4(),
$thread->getId(),
$userId,
$body,
$byUserId,
);
$this->eventService->pushEvent(new EventInside());
$this->commentRepository->save($comment);
$this->eventService->pushEvent(new EventAfter());
$this->eventService->releaseEvents();
return $comment;
}
}
$entity->methodA($x, $y);
$entity->methodB();
C сервисом они станут:
$entity->methodA($x, $y, $deferredEventService);
$entity->methodB($deferredEventService);