entityManager; } /** * @throws Exception */ public function getEntityMapper(): EntityFormMapper { if ($this->entityMapper === NULL) { if (!$this->getEntityManager()) { throw new Exception('Set entity manager first via setEntityManager() method.'); } $this->entityMapper = new EntityFormMapper($this->getEntityManager(), $this); } return $this->entityMapper; } public function setEntityManager(EntityManagerInterface $entityManager): self { $this->entityManager = $entityManager; return $this; } public function setEntity(Entity $entity): self { $this->entity = $entity; return $this; } public function getEntity(): ?object { return $this->entity; } /** * @throws Exception */ public function mapToForm(): void { if ($this->entity) { $this->getEntityMapper()->load($this->entity, $this); } } /** * @throws Exception */ public function mapToEntity($entity = null): void { $this->getEntityMapper()->save($entity ?: $this->entity, $this); } public function getComponentFormMapper(IComponent $component): ?Closure { return $this->componentFormMappers[spl_object_hash($component)] ?? null; } public function setComponentFormMapper(IComponent $component, Closure $formMapper): self { $this->componentFormMappers[spl_object_hash($component)] = $formMapper; return $this; } public function getComponentEntityMapper(IComponent $component): ?Closure { return $this->componentEntityMappers[spl_object_hash($component)] ?? null; } public function setComponentEntityMapper(IComponent $component, Closure $entityMapper): self { $this->componentEntityMappers[spl_object_hash($component)] = $entityMapper; return $this; } public function getComponentEntityFactory(IComponent $component): ?Closure { return $this->componentEntityFactories[spl_object_hash($component)] ?? null; } public function setComponentEntityFactory(IComponent $component, Closure $entityFactory): self { $this->componentEntityFactories[spl_object_hash($component)] = $entityFactory; return $this; } }