diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Repository | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Repository')
4 files changed, 123 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Repository/DefaultRepositoryFactory.php b/vendor/doctrine/orm/src/Repository/DefaultRepositoryFactory.php new file mode 100644 index 0000000..5c408fb --- /dev/null +++ b/vendor/doctrine/orm/src/Repository/DefaultRepositoryFactory.php | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Repository; | ||
| 6 | |||
| 7 | use Doctrine\ORM\EntityManagerInterface; | ||
| 8 | use Doctrine\ORM\EntityRepository; | ||
| 9 | use Doctrine\Persistence\ObjectRepository; | ||
| 10 | |||
| 11 | use function spl_object_id; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * This factory is used to create default repository objects for entities at runtime. | ||
| 15 | */ | ||
| 16 | final class DefaultRepositoryFactory implements RepositoryFactory | ||
| 17 | { | ||
| 18 | /** | ||
| 19 | * The list of EntityRepository instances. | ||
| 20 | * | ||
| 21 | * @var ObjectRepository[] | ||
| 22 | * @psalm-var array<string, EntityRepository> | ||
| 23 | */ | ||
| 24 | private array $repositoryList = []; | ||
| 25 | |||
| 26 | public function getRepository(EntityManagerInterface $entityManager, string $entityName): EntityRepository | ||
| 27 | { | ||
| 28 | $repositoryHash = $entityManager->getClassMetadata($entityName)->getName() . spl_object_id($entityManager); | ||
| 29 | |||
| 30 | return $this->repositoryList[$repositoryHash] ??= $this->createRepository($entityManager, $entityName); | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Create a new repository instance for an entity class. | ||
| 35 | * | ||
| 36 | * @param EntityManagerInterface $entityManager The EntityManager instance. | ||
| 37 | * @param string $entityName The name of the entity. | ||
| 38 | */ | ||
| 39 | private function createRepository( | ||
| 40 | EntityManagerInterface $entityManager, | ||
| 41 | string $entityName, | ||
| 42 | ): EntityRepository { | ||
| 43 | $metadata = $entityManager->getClassMetadata($entityName); | ||
| 44 | $repositoryClassName = $metadata->customRepositoryClassName | ||
| 45 | ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName(); | ||
| 46 | |||
| 47 | return new $repositoryClassName($entityManager, $metadata); | ||
| 48 | } | ||
| 49 | } | ||
diff --git a/vendor/doctrine/orm/src/Repository/Exception/InvalidFindByCall.php b/vendor/doctrine/orm/src/Repository/Exception/InvalidFindByCall.php new file mode 100644 index 0000000..c5dd015 --- /dev/null +++ b/vendor/doctrine/orm/src/Repository/Exception/InvalidFindByCall.php | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Repository\Exception; | ||
| 6 | |||
| 7 | use Doctrine\ORM\Exception\RepositoryException; | ||
| 8 | use LogicException; | ||
| 9 | |||
| 10 | final class InvalidFindByCall extends LogicException implements RepositoryException | ||
| 11 | { | ||
| 12 | public static function fromInverseSideUsage( | ||
| 13 | string $entityName, | ||
| 14 | string $associationFieldName, | ||
| 15 | ): self { | ||
| 16 | return new self( | ||
| 17 | "You cannot search for the association field '" . $entityName . '#' . $associationFieldName . "', " . | ||
| 18 | 'because it is the inverse side of an association. Find methods only work on owning side associations.', | ||
| 19 | ); | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/vendor/doctrine/orm/src/Repository/Exception/InvalidMagicMethodCall.php b/vendor/doctrine/orm/src/Repository/Exception/InvalidMagicMethodCall.php new file mode 100644 index 0000000..1da49cb --- /dev/null +++ b/vendor/doctrine/orm/src/Repository/Exception/InvalidMagicMethodCall.php | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Repository\Exception; | ||
| 6 | |||
| 7 | use Doctrine\ORM\Exception\RepositoryException; | ||
| 8 | use LogicException; | ||
| 9 | |||
| 10 | final class InvalidMagicMethodCall extends LogicException implements RepositoryException | ||
| 11 | { | ||
| 12 | public static function becauseFieldNotFoundIn( | ||
| 13 | string $entityName, | ||
| 14 | string $fieldName, | ||
| 15 | string $method, | ||
| 16 | ): self { | ||
| 17 | return new self( | ||
| 18 | "Entity '" . $entityName . "' has no field '" . $fieldName . "'. " . | ||
| 19 | "You can therefore not call '" . $method . "' on the entities' repository.", | ||
| 20 | ); | ||
| 21 | } | ||
| 22 | |||
| 23 | public static function onMissingParameter(string $methodName): self | ||
| 24 | { | ||
| 25 | return new self("You need to pass a parameter to '" . $methodName . "'"); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/vendor/doctrine/orm/src/Repository/RepositoryFactory.php b/vendor/doctrine/orm/src/Repository/RepositoryFactory.php new file mode 100644 index 0000000..e066eae --- /dev/null +++ b/vendor/doctrine/orm/src/Repository/RepositoryFactory.php | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Repository; | ||
| 6 | |||
| 7 | use Doctrine\ORM\EntityManagerInterface; | ||
| 8 | use Doctrine\ORM\EntityRepository; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * Interface for entity repository factory. | ||
| 12 | */ | ||
| 13 | interface RepositoryFactory | ||
| 14 | { | ||
| 15 | /** | ||
| 16 | * Gets the repository for an entity class. | ||
| 17 | * | ||
| 18 | * @param EntityManagerInterface $entityManager The EntityManager instance. | ||
| 19 | * @param class-string<T> $entityName The name of the entity. | ||
| 20 | * | ||
| 21 | * @return EntityRepository<T> | ||
| 22 | * | ||
| 23 | * @template T of object | ||
| 24 | */ | ||
| 25 | public function getRepository(EntityManagerInterface $entityManager, string $entityName): EntityRepository; | ||
| 26 | } | ||
