src/Manager/BaseManager.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Manager;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. abstract class BaseManager
  6. {
  7.     protected EntityManagerInterface $em;
  8.     protected ServiceEntityRepository $repository;
  9.     /**
  10.      * @param EntityManagerInterface $em
  11.      * @param ServiceEntityRepository $repository
  12.      */
  13.     public function __construct(EntityManagerInterface $emServiceEntityRepository $repository)
  14.     {
  15.         $this->em $em;
  16.         $this->repository $repository;
  17.     }
  18.     public function find(int $id)
  19.     {
  20.         return $this->repository->find($id);
  21.     }
  22.     public function findOneBy(array $criteria, array $orderBy null)
  23.     {
  24.         return $this->repository->findOneBy($criteria$orderBy);
  25.     }
  26.     public function findAll()
  27.     {
  28.         return $this->repository->findAll();
  29.     }
  30.     public function findBy(array $criteria, array $orderBy null$limit null$offset null)
  31.     {
  32.         return $this->repository->findBy($criteria$orderBy$limit$offset);
  33.     }
  34.     public function create()
  35.     {
  36.         return null;
  37.     }
  38.     public function save($entity)
  39.     {
  40.         $this->em->persist($entity);
  41.         $this->em->flush();
  42.         return $entity;
  43.     }
  44.     public function update($entity)
  45.     {
  46.         $this->em->persist($entity);
  47.         $this->em->flush();
  48.         return $entity;
  49.     }
  50.     public function delete($entity)
  51.     {
  52.         $this->em->remove($entity);
  53.         $this->em->flush();
  54.         return true;
  55.     }
  56. }