summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Repository
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Repository')
-rw-r--r--vendor/doctrine/orm/src/Repository/DefaultRepositoryFactory.php49
-rw-r--r--vendor/doctrine/orm/src/Repository/Exception/InvalidFindByCall.php21
-rw-r--r--vendor/doctrine/orm/src/Repository/Exception/InvalidMagicMethodCall.php27
-rw-r--r--vendor/doctrine/orm/src/Repository/RepositoryFactory.php26
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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Repository;
6
7use Doctrine\ORM\EntityManagerInterface;
8use Doctrine\ORM\EntityRepository;
9use Doctrine\Persistence\ObjectRepository;
10
11use function spl_object_id;
12
13/**
14 * This factory is used to create default repository objects for entities at runtime.
15 */
16final 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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Repository\Exception;
6
7use Doctrine\ORM\Exception\RepositoryException;
8use LogicException;
9
10final 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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Repository\Exception;
6
7use Doctrine\ORM\Exception\RepositoryException;
8use LogicException;
9
10final 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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Repository;
6
7use Doctrine\ORM\EntityManagerInterface;
8use Doctrine\ORM\EntityRepository;
9
10/**
11 * Interface for entity repository factory.
12 */
13interface 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}