*/ class EntityManager { protected EventDispatcherInterface $eventDispatcher; protected DoctrineEntityManager $entityManager; public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager) { $this->eventDispatcher = $eventDispatcher; $this->entityManager = $entityManager; } public function getRepository($className) { return $this->entityManager->getRepository($this->getEntityName($className)); } public function new($className) { return new $this->getEntityName($className); } public function create(EntityInterface $entity): self { $this->persist($entity); $this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT); return $this; } public function update(EntityInterface $entity): self { $this->persist($entity); $this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::UPDATE_EVENT); return $this; } public function delete(EntityInterface $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(EntityInterface $entity) { $this->entityManager->persist($entity); } public function getEntityName($className) { if (substr($className, -9) === 'Interface') { return $this->entityManager->getClassMetadata($className)->getName(); }else{ return $className; } } }