summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Id
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Id
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Id')
-rw-r--r--vendor/doctrine/orm/src/Id/AbstractIdGenerator.php28
-rw-r--r--vendor/doctrine/orm/src/Id/AssignedGenerator.php45
-rw-r--r--vendor/doctrine/orm/src/Id/BigIntegerIdentityGenerator.php25
-rw-r--r--vendor/doctrine/orm/src/Id/IdentityGenerator.php25
-rw-r--r--vendor/doctrine/orm/src/Id/SequenceGenerator.php112
5 files changed, 235 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Id/AbstractIdGenerator.php b/vendor/doctrine/orm/src/Id/AbstractIdGenerator.php
new file mode 100644
index 0000000..6d981f8
--- /dev/null
+++ b/vendor/doctrine/orm/src/Id/AbstractIdGenerator.php
@@ -0,0 +1,28 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Id;
6
7use Doctrine\ORM\EntityManagerInterface;
8
9abstract class AbstractIdGenerator
10{
11 /**
12 * Generates an identifier for an entity.
13 */
14 abstract public function generateId(EntityManagerInterface $em, object|null $entity): mixed;
15
16 /**
17 * Gets whether this generator is a post-insert generator which means that
18 * {@link generateId()} must be called after the entity has been inserted
19 * into the database.
20 *
21 * By default, this method returns FALSE. Generators that have this requirement
22 * must override this method and return TRUE.
23 */
24 public function isPostInsertGenerator(): bool
25 {
26 return false;
27 }
28}
diff --git a/vendor/doctrine/orm/src/Id/AssignedGenerator.php b/vendor/doctrine/orm/src/Id/AssignedGenerator.php
new file mode 100644
index 0000000..e11b341
--- /dev/null
+++ b/vendor/doctrine/orm/src/Id/AssignedGenerator.php
@@ -0,0 +1,45 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Id;
6
7use Doctrine\ORM\EntityManagerInterface;
8use Doctrine\ORM\Exception\EntityMissingAssignedId;
9
10/**
11 * Special generator for application-assigned identifiers (doesn't really generate anything).
12 */
13class AssignedGenerator extends AbstractIdGenerator
14{
15 /**
16 * Returns the identifier assigned to the given entity.
17 *
18 * {@inheritDoc}
19 *
20 * @throws EntityMissingAssignedId
21 */
22 public function generateId(EntityManagerInterface $em, object|null $entity): array
23 {
24 $class = $em->getClassMetadata($entity::class);
25 $idFields = $class->getIdentifierFieldNames();
26 $identifier = [];
27
28 foreach ($idFields as $idField) {
29 $value = $class->getFieldValue($entity, $idField);
30
31 if (! isset($value)) {
32 throw EntityMissingAssignedId::forField($entity, $idField);
33 }
34
35 if (isset($class->associationMappings[$idField])) {
36 // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
37 $value = $em->getUnitOfWork()->getSingleIdentifierValue($value);
38 }
39
40 $identifier[$idField] = $value;
41 }
42
43 return $identifier;
44 }
45}
diff --git a/vendor/doctrine/orm/src/Id/BigIntegerIdentityGenerator.php b/vendor/doctrine/orm/src/Id/BigIntegerIdentityGenerator.php
new file mode 100644
index 0000000..762a7cb
--- /dev/null
+++ b/vendor/doctrine/orm/src/Id/BigIntegerIdentityGenerator.php
@@ -0,0 +1,25 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Id;
6
7use Doctrine\ORM\EntityManagerInterface;
8
9/**
10 * Id generator that obtains IDs from special "identity" columns. These are columns
11 * that automatically get a database-generated, auto-incremented identifier on INSERT.
12 * This generator obtains the last insert id after such an insert.
13 */
14class BigIntegerIdentityGenerator extends AbstractIdGenerator
15{
16 public function generateId(EntityManagerInterface $em, object|null $entity): string
17 {
18 return (string) $em->getConnection()->lastInsertId();
19 }
20
21 public function isPostInsertGenerator(): bool
22 {
23 return true;
24 }
25}
diff --git a/vendor/doctrine/orm/src/Id/IdentityGenerator.php b/vendor/doctrine/orm/src/Id/IdentityGenerator.php
new file mode 100644
index 0000000..4610f66
--- /dev/null
+++ b/vendor/doctrine/orm/src/Id/IdentityGenerator.php
@@ -0,0 +1,25 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Id;
6
7use Doctrine\ORM\EntityManagerInterface;
8
9/**
10 * Id generator that obtains IDs from special "identity" columns. These are columns
11 * that automatically get a database-generated, auto-incremented identifier on INSERT.
12 * This generator obtains the last insert id after such an insert.
13 */
14class IdentityGenerator extends AbstractIdGenerator
15{
16 public function generateId(EntityManagerInterface $em, object|null $entity): int
17 {
18 return (int) $em->getConnection()->lastInsertId();
19 }
20
21 public function isPostInsertGenerator(): bool
22 {
23 return true;
24 }
25}
diff --git a/vendor/doctrine/orm/src/Id/SequenceGenerator.php b/vendor/doctrine/orm/src/Id/SequenceGenerator.php
new file mode 100644
index 0000000..659bb58
--- /dev/null
+++ b/vendor/doctrine/orm/src/Id/SequenceGenerator.php
@@ -0,0 +1,112 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Id;
6
7use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
8use Doctrine\Deprecations\Deprecation;
9use Doctrine\ORM\EntityManagerInterface;
10use Serializable;
11
12use function serialize;
13use function unserialize;
14
15/**
16 * Represents an ID generator that uses a database sequence.
17 */
18class SequenceGenerator extends AbstractIdGenerator implements Serializable
19{
20 private int $nextValue = 0;
21 private int|null $maxValue = null;
22
23 /**
24 * Initializes a new sequence generator.
25 *
26 * @param string $sequenceName The name of the sequence.
27 * @param int $allocationSize The allocation size of the sequence.
28 */
29 public function __construct(
30 private string $sequenceName,
31 private int $allocationSize,
32 ) {
33 }
34
35 public function generateId(EntityManagerInterface $em, object|null $entity): int
36 {
37 if ($this->maxValue === null || $this->nextValue === $this->maxValue) {
38 // Allocate new values
39 $connection = $em->getConnection();
40 $sql = $connection->getDatabasePlatform()->getSequenceNextValSQL($this->sequenceName);
41
42 if ($connection instanceof PrimaryReadReplicaConnection) {
43 $connection->ensureConnectedToPrimary();
44 }
45
46 $this->nextValue = (int) $connection->fetchOne($sql);
47 $this->maxValue = $this->nextValue + $this->allocationSize;
48 }
49
50 return $this->nextValue++;
51 }
52
53 /**
54 * Gets the maximum value of the currently allocated bag of values.
55 */
56 public function getCurrentMaxValue(): int|null
57 {
58 return $this->maxValue;
59 }
60
61 /**
62 * Gets the next value that will be returned by generate().
63 */
64 public function getNextValue(): int
65 {
66 return $this->nextValue;
67 }
68
69 /** @deprecated without replacement. */
70 final public function serialize(): string
71 {
72 Deprecation::trigger(
73 'doctrine/orm',
74 'https://github.com/doctrine/orm/pull/11468',
75 '%s() is deprecated, use __serialize() instead. %s won\'t implement the Serializable interface anymore in ORM 4.',
76 __METHOD__,
77 self::class,
78 );
79
80 return serialize($this->__serialize());
81 }
82
83 /** @return array<string, mixed> */
84 public function __serialize(): array
85 {
86 return [
87 'allocationSize' => $this->allocationSize,
88 'sequenceName' => $this->sequenceName,
89 ];
90 }
91
92 /** @deprecated without replacement. */
93 final public function unserialize(string $serialized): void
94 {
95 Deprecation::trigger(
96 'doctrine/orm',
97 'https://github.com/doctrine/orm/pull/11468',
98 '%s() is deprecated, use __unserialize() instead. %s won\'t implement the Serializable interface anymore in ORM 4.',
99 __METHOD__,
100 self::class,
101 );
102
103 $this->__unserialize(unserialize($serialized));
104 }
105
106 /** @param array<string, mixed> $data */
107 public function __unserialize(array $data): void
108 {
109 $this->sequenceName = $data['sequenceName'];
110 $this->allocationSize = $data['allocationSize'];
111 }
112}