NotificationRepository as a service

This commit is contained in:
Marc Ducobu 2021-06-15 18:57:56 +02:00
parent db545f9fe6
commit 49d022ef55
3 changed files with 39 additions and 21 deletions

View File

@ -19,14 +19,13 @@
namespace Chill\MainBundle\Entity; namespace Chill\MainBundle\Entity;
use App\Repository\Chill\MainBundle\Entity\NotificationRepository;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* @ORM\Entity(repositoryClass=NotificationRepository::class) * @ORM\Entity
* @ORM\Table( * @ORM\Table(
* name="chill_main_notification", * name="chill_main_notification",
* uniqueConstraints={ * uniqueConstraints={

View File

@ -20,20 +20,47 @@
namespace Chill\MainBundle\Repository; namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
/** final class NotificationRepository implements ObjectRepository
* @method Notification|null find($id, $lockMode = null, $lockVersion = null)
* @method Notification|null findOneBy(array $criteria, array $orderBy = null)
* @method Notification[] findAll()
* @method Notification[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class NotificationRepository extends ServiceEntityRepository
{ {
public function __construct(ManagerRegistry $registry) private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{ {
parent::__construct($registry, Notification::class); $this->repository = $entityManager->getRepository(Notification::class);
}
public function find($id, $lockMode = null, $lockVersion = null): ?Notification
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?Notification
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return Notification[]
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @return Notification[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
return Notification::class;
} }
} }

View File

@ -32,11 +32,3 @@ services:
- "Chill\\MainBundle\\Entity\\Center" - "Chill\\MainBundle\\Entity\\Center"
Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository' Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository'
chill.main.notification_repository:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- "Chill\\MainBundle\\Entity\\Notification"
Chill\MainBundle\Repository\NotificationRepository: '@chill.main.notification_repository'