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/Utility | |
| 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/Utility')
4 files changed, 270 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Utility/HierarchyDiscriminatorResolver.php b/vendor/doctrine/orm/src/Utility/HierarchyDiscriminatorResolver.php new file mode 100644 index 0000000..b682125 --- /dev/null +++ b/vendor/doctrine/orm/src/Utility/HierarchyDiscriminatorResolver.php | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Utility; | ||
| 6 | |||
| 7 | use Doctrine\ORM\EntityManagerInterface; | ||
| 8 | use Doctrine\Persistence\Mapping\ClassMetadata; | ||
| 9 | |||
| 10 | /** @internal This class exists only to avoid code duplication, do not reuse it externally */ | ||
| 11 | final class HierarchyDiscriminatorResolver | ||
| 12 | { | ||
| 13 | private function __construct() | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | /** | ||
| 18 | * This method is needed to make INSTANCEOF work correctly with inheritance: if the class at hand has inheritance, | ||
| 19 | * it extracts all the discriminators from the child classes and returns them | ||
| 20 | * | ||
| 21 | * @return null[] | ||
| 22 | * @psalm-return array<array-key, null> | ||
| 23 | */ | ||
| 24 | public static function resolveDiscriminatorsForClass( | ||
| 25 | ClassMetadata $rootClassMetadata, | ||
| 26 | EntityManagerInterface $entityManager, | ||
| 27 | ): array { | ||
| 28 | $hierarchyClasses = $rootClassMetadata->subClasses; | ||
| 29 | $hierarchyClasses[] = $rootClassMetadata->name; | ||
| 30 | |||
| 31 | $discriminators = []; | ||
| 32 | |||
| 33 | foreach ($hierarchyClasses as $class) { | ||
| 34 | $currentMetadata = $entityManager->getClassMetadata($class); | ||
| 35 | $currentDiscriminator = $currentMetadata->discriminatorValue; | ||
| 36 | |||
| 37 | if ($currentDiscriminator !== null) { | ||
| 38 | $discriminators[$currentDiscriminator] = null; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return $discriminators; | ||
| 43 | } | ||
| 44 | } | ||
diff --git a/vendor/doctrine/orm/src/Utility/IdentifierFlattener.php b/vendor/doctrine/orm/src/Utility/IdentifierFlattener.php new file mode 100644 index 0000000..3792d33 --- /dev/null +++ b/vendor/doctrine/orm/src/Utility/IdentifierFlattener.php | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Utility; | ||
| 6 | |||
| 7 | use BackedEnum; | ||
| 8 | use Doctrine\ORM\Mapping\ClassMetadata; | ||
| 9 | use Doctrine\ORM\UnitOfWork; | ||
| 10 | use Doctrine\Persistence\Mapping\ClassMetadataFactory; | ||
| 11 | |||
| 12 | use function assert; | ||
| 13 | use function implode; | ||
| 14 | use function is_a; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * The IdentifierFlattener utility now houses some of the identifier manipulation logic from unit of work, so that it | ||
| 18 | * can be re-used elsewhere. | ||
| 19 | */ | ||
| 20 | final class IdentifierFlattener | ||
| 21 | { | ||
| 22 | /** | ||
| 23 | * Initializes a new IdentifierFlattener instance, bound to the given EntityManager. | ||
| 24 | */ | ||
| 25 | public function __construct( | ||
| 26 | /** | ||
| 27 | * The UnitOfWork used to coordinate object-level transactions. | ||
| 28 | */ | ||
| 29 | private readonly UnitOfWork $unitOfWork, | ||
| 30 | /** | ||
| 31 | * The metadata factory, used to retrieve the ORM metadata of entity classes. | ||
| 32 | */ | ||
| 33 | private readonly ClassMetadataFactory $metadataFactory, | ||
| 34 | ) { | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures. | ||
| 39 | * | ||
| 40 | * @param mixed[] $id | ||
| 41 | * | ||
| 42 | * @return mixed[] | ||
| 43 | * @psalm-return array<string, mixed> | ||
| 44 | */ | ||
| 45 | public function flattenIdentifier(ClassMetadata $class, array $id): array | ||
| 46 | { | ||
| 47 | $flatId = []; | ||
| 48 | |||
| 49 | foreach ($class->identifier as $field) { | ||
| 50 | if (isset($class->associationMappings[$field]) && isset($id[$field]) && is_a($id[$field], $class->associationMappings[$field]->targetEntity)) { | ||
| 51 | $targetClassMetadata = $this->metadataFactory->getMetadataFor( | ||
| 52 | $class->associationMappings[$field]->targetEntity, | ||
| 53 | ); | ||
| 54 | assert($targetClassMetadata instanceof ClassMetadata); | ||
| 55 | |||
| 56 | if ($this->unitOfWork->isInIdentityMap($id[$field])) { | ||
| 57 | $associatedId = $this->flattenIdentifier($targetClassMetadata, $this->unitOfWork->getEntityIdentifier($id[$field])); | ||
| 58 | } else { | ||
| 59 | $associatedId = $this->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($id[$field])); | ||
| 60 | } | ||
| 61 | |||
| 62 | $flatId[$field] = implode(' ', $associatedId); | ||
| 63 | } elseif (isset($class->associationMappings[$field])) { | ||
| 64 | assert($class->associationMappings[$field]->isToOneOwningSide()); | ||
| 65 | $associatedId = []; | ||
| 66 | |||
| 67 | foreach ($class->associationMappings[$field]->joinColumns as $joinColumn) { | ||
| 68 | $associatedId[] = $id[$joinColumn->name]; | ||
| 69 | } | ||
| 70 | |||
| 71 | $flatId[$field] = implode(' ', $associatedId); | ||
| 72 | } else { | ||
| 73 | if ($id[$field] instanceof BackedEnum) { | ||
| 74 | $flatId[$field] = $id[$field]->value; | ||
| 75 | } else { | ||
| 76 | $flatId[$field] = $id[$field]; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return $flatId; | ||
| 82 | } | ||
| 83 | } | ||
diff --git a/vendor/doctrine/orm/src/Utility/LockSqlHelper.php b/vendor/doctrine/orm/src/Utility/LockSqlHelper.php new file mode 100644 index 0000000..7d135eb --- /dev/null +++ b/vendor/doctrine/orm/src/Utility/LockSqlHelper.php | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Utility; | ||
| 6 | |||
| 7 | use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
| 8 | use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
| 9 | use Doctrine\DBAL\Platforms\DB2Platform; | ||
| 10 | use Doctrine\DBAL\Platforms\PostgreSQLPlatform; | ||
| 11 | use Doctrine\DBAL\Platforms\SQLitePlatform; | ||
| 12 | use Doctrine\DBAL\Platforms\SQLServerPlatform; | ||
| 13 | |||
| 14 | /** @internal */ | ||
| 15 | trait LockSqlHelper | ||
| 16 | { | ||
| 17 | private function getReadLockSQL(AbstractPlatform $platform): string | ||
| 18 | { | ||
| 19 | return match (true) { | ||
| 20 | $platform instanceof AbstractMySQLPlatform => 'LOCK IN SHARE MODE', | ||
| 21 | $platform instanceof PostgreSQLPlatform => 'FOR SHARE', | ||
| 22 | default => $this->getWriteLockSQL($platform), | ||
| 23 | }; | ||
| 24 | } | ||
| 25 | |||
| 26 | private function getWriteLockSQL(AbstractPlatform $platform): string | ||
| 27 | { | ||
| 28 | return match (true) { | ||
| 29 | $platform instanceof DB2Platform => 'WITH RR USE AND KEEP UPDATE LOCKS', | ||
| 30 | $platform instanceof SQLitePlatform, | ||
| 31 | $platform instanceof SQLServerPlatform => '', | ||
| 32 | default => 'FOR UPDATE', | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/vendor/doctrine/orm/src/Utility/PersisterHelper.php b/vendor/doctrine/orm/src/Utility/PersisterHelper.php new file mode 100644 index 0000000..76e9242 --- /dev/null +++ b/vendor/doctrine/orm/src/Utility/PersisterHelper.php | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Utility; | ||
| 6 | |||
| 7 | use Doctrine\ORM\EntityManagerInterface; | ||
| 8 | use Doctrine\ORM\Mapping\ClassMetadata; | ||
| 9 | use Doctrine\ORM\Query\QueryException; | ||
| 10 | use RuntimeException; | ||
| 11 | |||
| 12 | use function sprintf; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * The PersisterHelper contains logic to infer binding types which is used in | ||
| 16 | * several persisters. | ||
| 17 | * | ||
| 18 | * @link www.doctrine-project.org | ||
| 19 | */ | ||
| 20 | class PersisterHelper | ||
| 21 | { | ||
| 22 | /** | ||
| 23 | * @return list<string> | ||
| 24 | * | ||
| 25 | * @throws QueryException | ||
| 26 | */ | ||
| 27 | public static function getTypeOfField(string $fieldName, ClassMetadata $class, EntityManagerInterface $em): array | ||
| 28 | { | ||
| 29 | if (isset($class->fieldMappings[$fieldName])) { | ||
| 30 | return [$class->fieldMappings[$fieldName]->type]; | ||
| 31 | } | ||
| 32 | |||
| 33 | if (! isset($class->associationMappings[$fieldName])) { | ||
| 34 | return []; | ||
| 35 | } | ||
| 36 | |||
| 37 | $assoc = $class->associationMappings[$fieldName]; | ||
| 38 | |||
| 39 | if (! $assoc->isOwningSide()) { | ||
| 40 | return self::getTypeOfField($assoc->mappedBy, $em->getClassMetadata($assoc->targetEntity), $em); | ||
| 41 | } | ||
| 42 | |||
| 43 | if ($assoc->isManyToManyOwningSide()) { | ||
| 44 | $joinData = $assoc->joinTable; | ||
| 45 | } else { | ||
| 46 | $joinData = $assoc; | ||
| 47 | } | ||
| 48 | |||
| 49 | $types = []; | ||
| 50 | $targetClass = $em->getClassMetadata($assoc->targetEntity); | ||
| 51 | |||
| 52 | foreach ($joinData->joinColumns as $joinColumn) { | ||
| 53 | $types[] = self::getTypeOfColumn($joinColumn->referencedColumnName, $targetClass, $em); | ||
| 54 | } | ||
| 55 | |||
| 56 | return $types; | ||
| 57 | } | ||
| 58 | |||
| 59 | /** @throws RuntimeException */ | ||
| 60 | public static function getTypeOfColumn(string $columnName, ClassMetadata $class, EntityManagerInterface $em): string | ||
| 61 | { | ||
| 62 | if (isset($class->fieldNames[$columnName])) { | ||
| 63 | $fieldName = $class->fieldNames[$columnName]; | ||
| 64 | |||
| 65 | if (isset($class->fieldMappings[$fieldName])) { | ||
| 66 | return $class->fieldMappings[$fieldName]->type; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | // iterate over to-one association mappings | ||
| 71 | foreach ($class->associationMappings as $assoc) { | ||
| 72 | if (! $assoc->isToOneOwningSide()) { | ||
| 73 | continue; | ||
| 74 | } | ||
| 75 | |||
| 76 | foreach ($assoc->joinColumns as $joinColumn) { | ||
| 77 | if ($joinColumn->name === $columnName) { | ||
| 78 | $targetColumnName = $joinColumn->referencedColumnName; | ||
| 79 | $targetClass = $em->getClassMetadata($assoc->targetEntity); | ||
| 80 | |||
| 81 | return self::getTypeOfColumn($targetColumnName, $targetClass, $em); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | // iterate over to-many association mappings | ||
| 87 | foreach ($class->associationMappings as $assoc) { | ||
| 88 | if (! $assoc->isManyToManyOwningSide()) { | ||
| 89 | continue; | ||
| 90 | } | ||
| 91 | |||
| 92 | foreach ($assoc->joinTable->joinColumns as $joinColumn) { | ||
| 93 | if ($joinColumn->name === $columnName) { | ||
| 94 | $targetColumnName = $joinColumn->referencedColumnName; | ||
| 95 | $targetClass = $em->getClassMetadata($assoc->targetEntity); | ||
| 96 | |||
| 97 | return self::getTypeOfColumn($targetColumnName, $targetClass, $em); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | throw new RuntimeException(sprintf( | ||
| 103 | 'Could not resolve type of column "%s" of class "%s"', | ||
| 104 | $columnName, | ||
| 105 | $class->getName(), | ||
| 106 | )); | ||
| 107 | } | ||
| 108 | } | ||
