summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php')
-rw-r--r--vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php b/vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php
new file mode 100644
index 0000000..306880d
--- /dev/null
+++ b/vendor/doctrine/orm/src/Mapping/ToManyAssociationMappingImplementation.php
@@ -0,0 +1,69 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Mapping;
6
7use LogicException;
8
9use function sprintf;
10
11/** @internal */
12trait ToManyAssociationMappingImplementation
13{
14 /**
15 * Specification of a field on target-entity that is used to index the
16 * collection by. This field HAS to be either the primary key or a unique
17 * column. Otherwise the collection does not contain all the entities that
18 * are actually related.
19 */
20 public string|null $indexBy = null;
21
22 /**
23 * A map of field names (of the target entity) to sorting directions
24 *
25 * @var array<string, 'asc'|'desc'>
26 */
27 public array $orderBy = [];
28
29 /** @return array<string, 'asc'|'desc'> */
30 final public function orderBy(): array
31 {
32 return $this->orderBy;
33 }
34
35 /** @psalm-assert-if-true !null $this->indexBy */
36 final public function isIndexed(): bool
37 {
38 return $this->indexBy !== null;
39 }
40
41 final public function indexBy(): string
42 {
43 if (! $this->isIndexed()) {
44 throw new LogicException(sprintf(
45 'This mapping is not indexed. Use %s::isIndexed() to check that before calling %s.',
46 self::class,
47 __METHOD__,
48 ));
49 }
50
51 return $this->indexBy;
52 }
53
54 /** @return list<string> */
55 public function __sleep(): array
56 {
57 $serialized = parent::__sleep();
58
59 if ($this->indexBy !== null) {
60 $serialized[] = 'indexBy';
61 }
62
63 if ($this->orderBy !== []) {
64 $serialized[] = 'orderBy';
65 }
66
67 return $serialized;
68 }
69}