Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace App\Model;
- use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
- use Doctrine\ORM\EntityNotFoundException;
- use Doctrine\Persistence\ManagerRegistry;
- /**
- * @template T of object
- * @phpstan-template T of object
- * @psalm-template T of object
- * @template T1
- * @template-extends ServiceEntityRepository<T>
- */
- abstract class GenericRepository extends ServiceEntityRepository
- {
- /**
- * @psalm-param class-string<T> $class
- */
- public function __construct(ManagerRegistry $registry, $class)
- {
- parent::__construct($registry, $class);
- }
- /**
- * @param T1 $id
- *
- * @return T
- * @psalm-return T
- * @phpstan-return T
- *
- * @throws \Doctrine\ORM\EntityNotFoundException
- */
- public function get($id)
- {
- return $this->find($id) ??
- throw EntityNotFoundException::fromClassNameAndIdentifier($this->getClassName(), [(string)$id]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement