em = $em; $this->stranslate = $stranlate; $this->masquerade = $masqueradeService; $this->repo = null; $this->getRepoClass(); } /** * @return null|string */ protected function getRepoClass() { if (is_null($this->repo)) { $metadata = $this->em->getClassMetadata($this->masquerade->getServiceClass()); $this->repo = $metadata->getName(); } return $this->repo; } /** * @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository */ public function getRepositoryService(){ $repo = $this->em->getRepository($this->getRepoClass()); return $repo; } /** * get class name * * @param bool $namespace (with or without namespace) * @return null|string */ protected function getClass(bool $namespace = true) { return $this->masquerade->getServiceClass($namespace); } /** * @param CustomCompanyInterface $company * @return CustomCompanyServiceInterface[]|null */ public function getServicesFor(CustomCompanyInterface $company){ $services = $this->getRepositoryService()->findBy(['company' => $company]); return $services; } /** * @param $pk * @return CustomCompanyServiceInterface|null */ public function getByPublicKey($pk){ return $this->getRepositoryService()->findOneBy(['publicKey' => $pk]); } /** * @param $element * @return CustomCompanyServiceInterface|null */ public function update(CustomCompanyServiceInterface $element) { return $this->quickUpdate($element); } /** * @param CustomCompanyServiceInterface $element * @return CustomCompanyServiceInterface|null */ public function quickUpdate(CustomCompanyServiceInterface $element) { if (!$this->em->contains($element)) { try { $this->em->persist($element); } catch (ORMException $e) { return null; } } try { $this->em->flush(); } catch (OptimisticLockException $e) { return null; } catch (ORMException $e) { return null; } return $element; } /** * @param CustomCompanyServiceInterface $element * @return boolean */ public function delete(CustomCompanyServiceInterface $element) { try { $this->em->remove($element); } catch (ORMException $e) { return false; } try { $this->em->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } }