*/ class EntityManager { protected EventDispatcherInterface $eventDispatcher; protected DoctrineEntityManager $entityManager; public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager) { $this->eventDispatcher = $eventDispatcher; $this->entityManager = $entityManager; } public function create(Entity $entity): self { $this->persist($entity); $this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT); return $this; } public function update(Entity $entity): self { $this->persist($entity); $this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::UPDATE_EVENT); return $this; } public function delete(Entity $entity): self { $this->remove($entity); $this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::DELETE_EVENT); return $this; } public function flush(): self { $this->entityManager->flush(); return $this; } public function clear(): self { $this->entityManager->clear(); return $this; } protected function persist(Entity $entity) { $this->entityManager->persist($entity); } }