vendor/doctrine/doctrine-bundle/Repository/ServiceEntityRepository.php line 28

Open in your IDE?
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use LogicException;
  6. /**
  7.  * Optional EntityRepository base class with a simplified constructor (for autowiring).
  8.  *
  9.  * To use in your class, inject the "registry" service and call
  10.  * the parent constructor. For example:
  11.  *
  12.  * class YourEntityRepository extends ServiceEntityRepository
  13.  * {
  14.  *     public function __construct(ManagerRegistry $registry)
  15.  *     {
  16.  *         parent::__construct($registry, YourEntity::class);
  17.  *     }
  18.  * }
  19.  */
  20. class ServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface
  21. {
  22.     /**
  23.      * @param string $entityClass The class name of the entity this repository manages
  24.      */
  25.     public function __construct(ManagerRegistry $registry$entityClass)
  26.     {
  27.         $manager $registry->getManagerForClass($entityClass);
  28.         if ($manager === null) {
  29.             throw new LogicException(sprintf(
  30.                 'Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.',
  31.                 $entityClass
  32.             ));
  33.         }
  34.         parent::__construct($manager$manager->getClassMetadata($entityClass));
  35.     }
  36. }