src/Repository/AbstractRepository.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. /**
  6.  * Abstract repository.
  7.  */
  8. abstract class AbstractRepository extends ServiceEntityRepository
  9. {
  10.     /**
  11.      * AbstractRepository constructor.
  12.      *
  13.      * @param ManagerRegistry $registry
  14.      */
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registry$this->getEntityClass());
  18.     }
  19.     /**
  20.      * Gets the entity class.
  21.      *
  22.      * @return string
  23.      */
  24.     protected function getEntityClass(): string
  25.     {
  26.         // removes the suffix "Repository"
  27.         $class preg_replace('/Repository$/''', static::class);
  28.         // replaces "Repository" with "Entity" in the namespace
  29.         return str_replace('\\Repository\\''\\Entity\\'$class);
  30.     }
  31. }