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

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. use Symfony\Component\VarExporter\LazyGhostTrait;
  7. use function sprintf;
  8. use function trait_exists;
  9. if (trait_exists(LazyGhostTrait::class)) {
  10.     /**
  11.      * @template T of object
  12.      * @template-extends LazyServiceEntityRepository<T>
  13.      */
  14.     class ServiceEntityRepository extends LazyServiceEntityRepository
  15.     {
  16.     }
  17. } else {
  18.     /**
  19.      * Optional EntityRepository base class with a simplified constructor (for autowiring).
  20.      *
  21.      * To use in your class, inject the "registry" service and call
  22.      * the parent constructor. For example:
  23.      *
  24.      * class YourEntityRepository extends ServiceEntityRepository
  25.      * {
  26.      *     public function __construct(ManagerRegistry $registry)
  27.      *     {
  28.      *         parent::__construct($registry, YourEntity::class);
  29.      *     }
  30.      * }
  31.      *
  32.      * @template T of object
  33.      * @template-extends EntityRepository<T>
  34.      */
  35.     class ServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface
  36.     {
  37.         /**
  38.          * @param string $entityClass The class name of the entity this repository manages
  39.          * @psalm-param class-string<T> $entityClass
  40.          */
  41.         public function __construct(ManagerRegistry $registrystring $entityClass)
  42.         {
  43.             $manager $registry->getManagerForClass($entityClass);
  44.             if ($manager === null) {
  45.                 throw new LogicException(sprintf(
  46.                     '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.',
  47.                     $entityClass
  48.                 ));
  49.             }
  50.             parent::__construct($manager$manager->getClassMetadata($entityClass));
  51.         }
  52.     }
  53. }