From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orm/src/Mapping/Builder/AssociationBuilder.php | 171 +++++++++ .../src/Mapping/Builder/ClassMetadataBuilder.php | 426 +++++++++++++++++++++ .../orm/src/Mapping/Builder/EmbeddedBuilder.php | 46 +++ .../src/Mapping/Builder/EntityListenerBuilder.php | 55 +++ .../orm/src/Mapping/Builder/FieldBuilder.php | 243 ++++++++++++ .../Builder/ManyToManyAssociationBuilder.php | 73 ++++ .../Builder/OneToManyAssociationBuilder.php | 46 +++ 7 files changed, 1060 insertions(+) create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/AssociationBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/ClassMetadataBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/EmbeddedBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/EntityListenerBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/ManyToManyAssociationBuilder.php create mode 100644 vendor/doctrine/orm/src/Mapping/Builder/OneToManyAssociationBuilder.php (limited to 'vendor/doctrine/orm/src/Mapping/Builder') diff --git a/vendor/doctrine/orm/src/Mapping/Builder/AssociationBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/AssociationBuilder.php new file mode 100644 index 0000000..ea9e13c --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/AssociationBuilder.php @@ -0,0 +1,171 @@ +mapping['mappedBy'] = $fieldName; + + return $this; + } + + /** @return $this */ + public function inversedBy(string $fieldName): static + { + $this->mapping['inversedBy'] = $fieldName; + + return $this; + } + + /** @return $this */ + public function cascadeAll(): static + { + $this->mapping['cascade'] = ['ALL']; + + return $this; + } + + /** @return $this */ + public function cascadePersist(): static + { + $this->mapping['cascade'][] = 'persist'; + + return $this; + } + + /** @return $this */ + public function cascadeRemove(): static + { + $this->mapping['cascade'][] = 'remove'; + + return $this; + } + + /** @return $this */ + public function cascadeDetach(): static + { + $this->mapping['cascade'][] = 'detach'; + + return $this; + } + + /** @return $this */ + public function cascadeRefresh(): static + { + $this->mapping['cascade'][] = 'refresh'; + + return $this; + } + + /** @return $this */ + public function fetchExtraLazy(): static + { + $this->mapping['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY; + + return $this; + } + + /** @return $this */ + public function fetchEager(): static + { + $this->mapping['fetch'] = ClassMetadata::FETCH_EAGER; + + return $this; + } + + /** @return $this */ + public function fetchLazy(): static + { + $this->mapping['fetch'] = ClassMetadata::FETCH_LAZY; + + return $this; + } + + /** + * Add Join Columns. + * + * @return $this + */ + public function addJoinColumn( + string $columnName, + string $referencedColumnName, + bool $nullable = true, + bool $unique = false, + string|null $onDelete = null, + string|null $columnDef = null, + ): static { + $this->joinColumns[] = [ + 'name' => $columnName, + 'referencedColumnName' => $referencedColumnName, + 'nullable' => $nullable, + 'unique' => $unique, + 'onDelete' => $onDelete, + 'columnDefinition' => $columnDef, + ]; + + return $this; + } + + /** + * Sets field as primary key. + * + * @return $this + */ + public function makePrimaryKey(): static + { + $this->mapping['id'] = true; + + return $this; + } + + /** + * Removes orphan entities when detached from their parent. + * + * @return $this + */ + public function orphanRemoval(): static + { + $this->mapping['orphanRemoval'] = true; + + return $this; + } + + /** @throws InvalidArgumentException */ + public function build(): ClassMetadataBuilder + { + $mapping = $this->mapping; + if ($this->joinColumns) { + $mapping['joinColumns'] = $this->joinColumns; + } + + $cm = $this->builder->getClassMetadata(); + if ($this->type === ClassMetadata::MANY_TO_ONE) { + $cm->mapManyToOne($mapping); + } elseif ($this->type === ClassMetadata::ONE_TO_ONE) { + $cm->mapOneToOne($mapping); + } else { + throw new InvalidArgumentException('Type should be a ToOne Association here'); + } + + return $this->builder; + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/ClassMetadataBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/ClassMetadataBuilder.php new file mode 100644 index 0000000..b9d3cc8 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/ClassMetadataBuilder.php @@ -0,0 +1,426 @@ +cm; + } + + /** + * Marks the class as mapped superclass. + * + * @return $this + */ + public function setMappedSuperClass(): static + { + $this->cm->isMappedSuperclass = true; + $this->cm->isEmbeddedClass = false; + + return $this; + } + + /** + * Marks the class as embeddable. + * + * @return $this + */ + public function setEmbeddable(): static + { + $this->cm->isEmbeddedClass = true; + $this->cm->isMappedSuperclass = false; + + return $this; + } + + /** + * Adds and embedded class + * + * @param class-string $class + * + * @return $this + */ + public function addEmbedded(string $fieldName, string $class, string|false|null $columnPrefix = null): static + { + $this->cm->mapEmbedded( + [ + 'fieldName' => $fieldName, + 'class' => $class, + 'columnPrefix' => $columnPrefix, + ], + ); + + return $this; + } + + /** + * Sets custom Repository class name. + * + * @return $this + */ + public function setCustomRepositoryClass(string $repositoryClassName): static + { + $this->cm->setCustomRepositoryClass($repositoryClassName); + + return $this; + } + + /** + * Marks class read only. + * + * @return $this + */ + public function setReadOnly(): static + { + $this->cm->markReadOnly(); + + return $this; + } + + /** + * Sets the table name. + * + * @return $this + */ + public function setTable(string $name): static + { + $this->cm->setPrimaryTable(['name' => $name]); + + return $this; + } + + /** + * Adds Index. + * + * @psalm-param list $columns + * + * @return $this + */ + public function addIndex(array $columns, string $name): static + { + if (! isset($this->cm->table['indexes'])) { + $this->cm->table['indexes'] = []; + } + + $this->cm->table['indexes'][$name] = ['columns' => $columns]; + + return $this; + } + + /** + * Adds Unique Constraint. + * + * @psalm-param list $columns + * + * @return $this + */ + public function addUniqueConstraint(array $columns, string $name): static + { + if (! isset($this->cm->table['uniqueConstraints'])) { + $this->cm->table['uniqueConstraints'] = []; + } + + $this->cm->table['uniqueConstraints'][$name] = ['columns' => $columns]; + + return $this; + } + + /** + * Sets class as root of a joined table inheritance hierarchy. + * + * @return $this + */ + public function setJoinedTableInheritance(): static + { + $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_JOINED); + + return $this; + } + + /** + * Sets class as root of a single table inheritance hierarchy. + * + * @return $this + */ + public function setSingleTableInheritance(): static + { + $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); + + return $this; + } + + /** + * Sets the discriminator column details. + * + * @psalm-param class-string|null $enumType + * @psalm-param array $options + * + * @return $this + */ + public function setDiscriminatorColumn( + string $name, + string $type = 'string', + int $length = 255, + string|null $columnDefinition = null, + string|null $enumType = null, + array $options = [], + ): static { + $this->cm->setDiscriminatorColumn( + [ + 'name' => $name, + 'type' => $type, + 'length' => $length, + 'columnDefinition' => $columnDefinition, + 'enumType' => $enumType, + 'options' => $options, + ], + ); + + return $this; + } + + /** + * Adds a subclass to this inheritance hierarchy. + * + * @return $this + */ + public function addDiscriminatorMapClass(string $name, string $class): static + { + $this->cm->addDiscriminatorMapClass($name, $class); + + return $this; + } + + /** + * Sets deferred explicit change tracking policy. + * + * @return $this + */ + public function setChangeTrackingPolicyDeferredExplicit(): static + { + $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT); + + return $this; + } + + /** + * Adds lifecycle event. + * + * @return $this + */ + public function addLifecycleEvent(string $methodName, string $event): static + { + $this->cm->addLifecycleCallback($methodName, $event); + + return $this; + } + + /** + * Adds Field. + * + * @psalm-param array $mapping + * + * @return $this + */ + public function addField(string $name, string $type, array $mapping = []): static + { + $mapping['fieldName'] = $name; + $mapping['type'] = $type; + + $this->cm->mapField($mapping); + + return $this; + } + + /** + * Creates a field builder. + */ + public function createField(string $name, string $type): FieldBuilder + { + return new FieldBuilder( + $this, + [ + 'fieldName' => $name, + 'type' => $type, + ], + ); + } + + /** + * Creates an embedded builder. + */ + public function createEmbedded(string $fieldName, string $class): EmbeddedBuilder + { + return new EmbeddedBuilder( + $this, + [ + 'fieldName' => $fieldName, + 'class' => $class, + 'columnPrefix' => null, + ], + ); + } + + /** + * Adds a simple many to one association, optionally with the inversed by field. + */ + public function addManyToOne( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { + $builder = $this->createManyToOne($name, $targetEntity); + + if ($inversedBy !== null) { + $builder->inversedBy($inversedBy); + } + + return $builder->build(); + } + + /** + * Creates a ManyToOne Association Builder. + * + * Note: This method does not add the association, you have to call build() on the AssociationBuilder. + */ + public function createManyToOne(string $name, string $targetEntity): AssociationBuilder + { + return new AssociationBuilder( + $this, + [ + 'fieldName' => $name, + 'targetEntity' => $targetEntity, + ], + ClassMetadata::MANY_TO_ONE, + ); + } + + /** + * Creates a OneToOne Association Builder. + */ + public function createOneToOne(string $name, string $targetEntity): AssociationBuilder + { + return new AssociationBuilder( + $this, + [ + 'fieldName' => $name, + 'targetEntity' => $targetEntity, + ], + ClassMetadata::ONE_TO_ONE, + ); + } + + /** + * Adds simple inverse one-to-one association. + */ + public function addInverseOneToOne(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder + { + $builder = $this->createOneToOne($name, $targetEntity); + $builder->mappedBy($mappedBy); + + return $builder->build(); + } + + /** + * Adds simple owning one-to-one association. + */ + public function addOwningOneToOne( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { + $builder = $this->createOneToOne($name, $targetEntity); + + if ($inversedBy !== null) { + $builder->inversedBy($inversedBy); + } + + return $builder->build(); + } + + /** + * Creates a ManyToMany Association Builder. + */ + public function createManyToMany(string $name, string $targetEntity): ManyToManyAssociationBuilder + { + return new ManyToManyAssociationBuilder( + $this, + [ + 'fieldName' => $name, + 'targetEntity' => $targetEntity, + ], + ClassMetadata::MANY_TO_MANY, + ); + } + + /** + * Adds a simple owning many to many association. + */ + public function addOwningManyToMany( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { + $builder = $this->createManyToMany($name, $targetEntity); + + if ($inversedBy !== null) { + $builder->inversedBy($inversedBy); + } + + return $builder->build(); + } + + /** + * Adds a simple inverse many to many association. + */ + public function addInverseManyToMany(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder + { + $builder = $this->createManyToMany($name, $targetEntity); + $builder->mappedBy($mappedBy); + + return $builder->build(); + } + + /** + * Creates a one to many association builder. + */ + public function createOneToMany(string $name, string $targetEntity): OneToManyAssociationBuilder + { + return new OneToManyAssociationBuilder( + $this, + [ + 'fieldName' => $name, + 'targetEntity' => $targetEntity, + ], + ClassMetadata::ONE_TO_MANY, + ); + } + + /** + * Adds simple OneToMany association. + */ + public function addOneToMany(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder + { + $builder = $this->createOneToMany($name, $targetEntity); + $builder->mappedBy($mappedBy); + + return $builder->build(); + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/EmbeddedBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/EmbeddedBuilder.php new file mode 100644 index 0000000..b9d2127 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/EmbeddedBuilder.php @@ -0,0 +1,46 @@ +mapping['columnPrefix'] = $columnPrefix; + + return $this; + } + + /** + * Finalizes this embeddable and attach it to the ClassMetadata. + * + * Without this call an EmbeddedBuilder has no effect on the ClassMetadata. + */ + public function build(): ClassMetadataBuilder + { + $cm = $this->builder->getClassMetadata(); + + $cm->mapEmbedded($this->mapping); + + return $this->builder; + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/EntityListenerBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/EntityListenerBuilder.php new file mode 100644 index 0000000..a0b14b9 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/EntityListenerBuilder.php @@ -0,0 +1,55 @@ + true, + Events::postRemove => true, + Events::prePersist => true, + Events::postPersist => true, + Events::preUpdate => true, + Events::postUpdate => true, + Events::postLoad => true, + Events::preFlush => true, + ]; + + /** + * Lookup the entity class to find methods that match to event lifecycle names + * + * @param ClassMetadata $metadata The entity metadata. + * @param string $className The listener class name. + * + * @throws MappingException When the listener class not found. + */ + public static function bindEntityListener(ClassMetadata $metadata, string $className): void + { + $class = $metadata->fullyQualifiedClassName($className); + + if (! class_exists($class)) { + throw MappingException::entityListenerClassNotFound($class, $className); + } + + foreach (get_class_methods($class) as $method) { + if (! isset(self::EVENTS[$method])) { + continue; + } + + $metadata->addEntityListener($method, $class, $method); + } + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php new file mode 100644 index 0000000..8326ff5 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php @@ -0,0 +1,243 @@ +mapping['length'] = $length; + + return $this; + } + + /** + * Sets nullable. + * + * @return $this + */ + public function nullable(bool $flag = true): static + { + $this->mapping['nullable'] = $flag; + + return $this; + } + + /** + * Sets Unique. + * + * @return $this + */ + public function unique(bool $flag = true): static + { + $this->mapping['unique'] = $flag; + + return $this; + } + + /** + * Sets column name. + * + * @return $this + */ + public function columnName(string $name): static + { + $this->mapping['columnName'] = $name; + + return $this; + } + + /** + * Sets Precision. + * + * @return $this + */ + public function precision(int $p): static + { + $this->mapping['precision'] = $p; + + return $this; + } + + /** + * Sets insertable. + * + * @return $this + */ + public function insertable(bool $flag = true): self + { + if (! $flag) { + $this->mapping['notInsertable'] = true; + } + + return $this; + } + + /** + * Sets updatable. + * + * @return $this + */ + public function updatable(bool $flag = true): self + { + if (! $flag) { + $this->mapping['notUpdatable'] = true; + } + + return $this; + } + + /** + * Sets scale. + * + * @return $this + */ + public function scale(int $s): static + { + $this->mapping['scale'] = $s; + + return $this; + } + + /** + * Sets field as primary key. + * + * @return $this + */ + public function makePrimaryKey(): static + { + $this->mapping['id'] = true; + + return $this; + } + + /** + * Sets an option. + * + * @return $this + */ + public function option(string $name, mixed $value): static + { + $this->mapping['options'][$name] = $value; + + return $this; + } + + /** @return $this */ + public function generatedValue(string $strategy = 'AUTO'): static + { + $this->generatedValue = $strategy; + + return $this; + } + + /** + * Sets field versioned. + * + * @return $this + */ + public function isVersionField(): static + { + $this->version = true; + + return $this; + } + + /** + * Sets Sequence Generator. + * + * @return $this + */ + public function setSequenceGenerator(string $sequenceName, int $allocationSize = 1, int $initialValue = 1): static + { + $this->sequenceDef = [ + 'sequenceName' => $sequenceName, + 'allocationSize' => $allocationSize, + 'initialValue' => $initialValue, + ]; + + return $this; + } + + /** + * Sets column definition. + * + * @return $this + */ + public function columnDefinition(string $def): static + { + $this->mapping['columnDefinition'] = $def; + + return $this; + } + + /** + * Set the FQCN of the custom ID generator. + * This class must extend \Doctrine\ORM\Id\AbstractIdGenerator. + * + * @return $this + */ + public function setCustomIdGenerator(string $customIdGenerator): static + { + $this->customIdGenerator = $customIdGenerator; + + return $this; + } + + /** + * Finalizes this field and attach it to the ClassMetadata. + * + * Without this call a FieldBuilder has no effect on the ClassMetadata. + */ + public function build(): ClassMetadataBuilder + { + $cm = $this->builder->getClassMetadata(); + if ($this->generatedValue) { + $cm->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $this->generatedValue)); + } + + if ($this->version) { + $cm->setVersionMapping($this->mapping); + } + + $cm->mapField($this->mapping); + if ($this->sequenceDef) { + $cm->setSequenceGeneratorDefinition($this->sequenceDef); + } + + if ($this->customIdGenerator) { + $cm->setCustomGeneratorDefinition(['class' => $this->customIdGenerator]); + } + + return $this->builder; + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/ManyToManyAssociationBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/ManyToManyAssociationBuilder.php new file mode 100644 index 0000000..b83a8ba --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/ManyToManyAssociationBuilder.php @@ -0,0 +1,73 @@ +joinTableName = $name; + + return $this; + } + + /** + * Adds Inverse Join Columns. + * + * @return $this + */ + public function addInverseJoinColumn( + string $columnName, + string $referencedColumnName, + bool $nullable = true, + bool $unique = false, + string|null $onDelete = null, + string|null $columnDef = null, + ): static { + $this->inverseJoinColumns[] = [ + 'name' => $columnName, + 'referencedColumnName' => $referencedColumnName, + 'nullable' => $nullable, + 'unique' => $unique, + 'onDelete' => $onDelete, + 'columnDefinition' => $columnDef, + ]; + + return $this; + } + + public function build(): ClassMetadataBuilder + { + $mapping = $this->mapping; + $mapping['joinTable'] = []; + if ($this->joinColumns) { + $mapping['joinTable']['joinColumns'] = $this->joinColumns; + } + + if ($this->inverseJoinColumns) { + $mapping['joinTable']['inverseJoinColumns'] = $this->inverseJoinColumns; + } + + if ($this->joinTableName) { + $mapping['joinTable']['name'] = $this->joinTableName; + } + + $cm = $this->builder->getClassMetadata(); + $cm->mapManyToMany($mapping); + + return $this->builder; + } +} diff --git a/vendor/doctrine/orm/src/Mapping/Builder/OneToManyAssociationBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/OneToManyAssociationBuilder.php new file mode 100644 index 0000000..077c558 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/OneToManyAssociationBuilder.php @@ -0,0 +1,46 @@ + $fieldNames + * + * @return $this + */ + public function setOrderBy(array $fieldNames): static + { + $this->mapping['orderBy'] = $fieldNames; + + return $this; + } + + /** @return $this */ + public function setIndexBy(string $fieldName): static + { + $this->mapping['indexBy'] = $fieldName; + + return $this; + } + + public function build(): ClassMetadataBuilder + { + $mapping = $this->mapping; + if ($this->joinColumns) { + $mapping['joinColumns'] = $this->joinColumns; + } + + $cm = $this->builder->getClassMetadata(); + $cm->mapOneToMany($mapping); + + return $this->builder; + } +} -- cgit v1.2.3