Advertisement
Guest User

Untitled

a guest
Feb 13th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Model;
  6.  
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\ORM\EntityNotFoundException;
  9. use Doctrine\Persistence\ManagerRegistry;
  10.  
  11. /**
  12.  * @template T of object
  13.  * @phpstan-template T of object
  14.  * @psalm-template T of object
  15.  * @template T1
  16.  * @template-extends ServiceEntityRepository<T>
  17.  */
  18. abstract class GenericRepository extends ServiceEntityRepository
  19. {
  20.     /**
  21.      * @psalm-param class-string<T> $class
  22.      */
  23.     public function __construct(ManagerRegistry $registry, $class)
  24.     {
  25.         parent::__construct($registry, $class);
  26.     }
  27.  
  28.     /**
  29.      * @param T1 $id
  30.      *
  31.      * @return T
  32.      * @psalm-return T
  33.      * @phpstan-return T
  34.      *
  35.      * @throws \Doctrine\ORM\EntityNotFoundException
  36.      */
  37.     public function get($id)
  38.     {
  39.         return $this->find($id) ??
  40.             throw EntityNotFoundException::fromClassNameAndIdentifier($this->getClassName(), [(string)$id]);
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement