/** * @param EntityManager $em */ public function __construct(EntityManager $em) { $this->em = $em; $this->db = $em->getConnection(); $this->platform = $this->db->getDatabasePlatform(); $this->quotes = $em->getConfiguration()->getQuoteStrategy(); $this->uow = $this->em->getUnitOfWork(); }
/** * Save entity into DB * * @param BaseEntity $baseEntity * @return BaseEntity * @throws \Exception */ protected function saveEntity(BaseEntity $baseEntity) { $isPersisted = UnitOfWork::STATE_MANAGED === $this->entityManager->getUnitOfWork()->getEntityState($baseEntity); if ($isPersisted) { $this->entityManager->merge($baseEntity); } else { $this->entityManager->persist($baseEntity); } $this->entityManager->flush(); return $baseEntity; }
/** * @param mixed $object * @return string[] */ public function getPrimaryKeyByObject($object) { return array(self::ENTITY_CLASS => $this->entityManager->getClassMetadata(get_class($object))->name, self::PRIMARY_KEY => $this->entityManager->getUnitOfWork()->getSingleIdentifierValue($object)); }