-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
438 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\Repository; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use LogicException; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* Optional EntityRepository base class with a simplified constructor (for autowiring). | ||
* | ||
* To use in your class, inject the "registry" service and call | ||
* the parent constructor. For example: | ||
* | ||
* class YourEntityRepository extends ServiceEntityRepository | ||
* { | ||
* public function __construct(ManagerRegistry $registry) | ||
* { | ||
* parent::__construct($registry, YourEntity::class); | ||
* } | ||
* } | ||
* | ||
* @internal Extend {@see ServiceEntityRepository} instead. | ||
* | ||
* @template T of object | ||
* @template-extends EntityRepository<T> | ||
*/ | ||
class LegacyServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface | ||
{ | ||
/** | ||
* @param string $entityClass The class name of the entity this repository manages | ||
* @psalm-param class-string<T> $entityClass | ||
*/ | ||
public function __construct(ManagerRegistry $registry, string $entityClass) | ||
{ | ||
$manager = $registry->getManagerForClass($entityClass); | ||
|
||
if ($manager === null) { | ||
throw new LogicException(sprintf( | ||
'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.', | ||
$entityClass, | ||
)); | ||
} | ||
|
||
parent::__construct($manager, $manager->getClassMetadata($entityClass)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\Repository; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\ORM\Repository\RepositoryFactory; | ||
use Doctrine\Persistence\ObjectRepository; | ||
use ReflectionMethod; | ||
|
||
if ((new ReflectionMethod(RepositoryFactory::class, 'getRepository'))->hasReturnType()) { | ||
/** @internal */ | ||
trait RepositoryFactoryCompatibility | ||
{ | ||
/** | ||
* Gets the repository for an entity class. | ||
* | ||
* @param class-string<T> $entityName | ||
* | ||
* @return EntityRepository<T> | ||
* | ||
* @template T of object | ||
* | ||
* @psalm-suppress MethodSignatureMismatch | ||
*/ | ||
public function getRepository(EntityManagerInterface $entityManager, string $entityName): EntityRepository | ||
{ | ||
return $this->doGetRepository($entityManager, $entityName, true); | ||
} | ||
} | ||
} else { | ||
/** @internal */ | ||
trait RepositoryFactoryCompatibility | ||
{ | ||
/** {@inheritDoc} */ | ||
public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository | ||
{ | ||
return $this->doGetRepository($entityManager, $entityName, false); | ||
} | ||
} | ||
} |
Oops, something went wrong.