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 --- .../doctrine/orm/src/Mapping/MappingException.php | 691 +++++++++++++++++++++ 1 file changed, 691 insertions(+) create mode 100644 vendor/doctrine/orm/src/Mapping/MappingException.php (limited to 'vendor/doctrine/orm/src/Mapping/MappingException.php') diff --git a/vendor/doctrine/orm/src/Mapping/MappingException.php b/vendor/doctrine/orm/src/Mapping/MappingException.php new file mode 100644 index 0000000..9b73242 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/MappingException.php @@ -0,0 +1,691 @@ + $map + */ + public static function duplicateDiscriminatorEntry(string $className, array $entries, array $map): self + { + return new self( + 'The entries ' . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " . + 'If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. ' . + 'The entries of the current map are: @DiscriminatorMap({' . implode(', ', array_map( + static fn ($a, $b) => sprintf("'%s': '%s'", $a, $b), + array_keys($map), + array_values($map), + )) . '})', + ); + } + + /** + * @param class-string $rootEntityClass + * @param class-string $childEntityClass + */ + public static function missingInheritanceTypeDeclaration(string $rootEntityClass, string $childEntityClass): self + { + return new self(sprintf( + "Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared.", + $childEntityClass, + $rootEntityClass, + )); + } + + public static function missingDiscriminatorMap(string $className): self + { + return new self(sprintf( + "Entity class '%s' is using inheritance but no discriminator map was defined.", + $className, + )); + } + + public static function missingDiscriminatorColumn(string $className): self + { + return new self(sprintf( + "Entity class '%s' is using inheritance but no discriminator column was defined.", + $className, + )); + } + + public static function invalidDiscriminatorColumnType(string $className, string $type): self + { + return new self(sprintf( + "Discriminator column type on entity class '%s' is not allowed to be '%s'. 'string' or 'integer' type variables are suggested!", + $className, + $type, + )); + } + + public static function nameIsMandatoryForDiscriminatorColumns(string $className): self + { + return new self(sprintf("Discriminator column name on entity class '%s' is not defined.", $className)); + } + + public static function cannotVersionIdField(string $className, string $fieldName): self + { + return new self(sprintf( + "Setting Id field '%s' as versionable in entity class '%s' is not supported.", + $fieldName, + $className, + )); + } + + public static function duplicateColumnName(string $className, string $columnName): self + { + return new self("Duplicate definition of column '" . $columnName . "' on entity '" . $className . "' in a field or discriminator column mapping."); + } + + public static function illegalToManyAssociationOnMappedSuperclass(string $className, string $field): self + { + return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '" . $className . '#' . $field . "'."); + } + + public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId(string $className, string $targetEntity, string $targetField): self + { + return new self("It is not possible to map entity '" . $className . "' with a composite primary key " . + "as part of the primary key of another entity '" . $targetEntity . '#' . $targetField . "'."); + } + + public static function noSingleAssociationJoinColumnFound(string $className, string $field): self + { + return new self(sprintf("'%s#%s' is not an association with a single join column.", $className, $field)); + } + + public static function noFieldNameFoundForColumn(string $className, string $column): self + { + return new self(sprintf( + "Cannot find a field on '%s' that is mapped to column '%s'. Either the " . + 'field does not exist or an association exists but it has multiple join columns.', + $className, + $column, + )); + } + + public static function illegalOrphanRemovalOnIdentifierAssociation(string $className, string $field): self + { + return new self(sprintf( + "The orphan removal option is not allowed on an association that is part of the identifier in '%s#%s'.", + $className, + $field, + )); + } + + public static function illegalOrphanRemoval(string $className, string $field): self + { + return new self('Orphan removal is only allowed on one-to-one and one-to-many ' . + 'associations, but ' . $className . '#' . $field . ' is not.'); + } + + public static function illegalInverseIdentifierAssociation(string $className, string $field): self + { + return new self(sprintf( + "An inverse association is not allowed to be identifier in '%s#%s'.", + $className, + $field, + )); + } + + public static function illegalToManyIdentifierAssociation(string $className, string $field): self + { + return new self(sprintf( + "Many-to-many or one-to-many associations are not allowed to be identifier in '%s#%s'.", + $className, + $field, + )); + } + + public static function noInheritanceOnMappedSuperClass(string $className): self + { + return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'."); + } + + public static function mappedClassNotPartOfDiscriminatorMap(string $className, string $rootClassName): self + { + return new self( + "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " . + "to be properly mapped in the inheritance hierarchy. Alternatively you can make '" . $className . "' an abstract class " . + 'to avoid this exception from occurring.', + ); + } + + public static function lifecycleCallbackMethodNotFound(string $className, string $methodName): self + { + return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback."); + } + + /** @param class-string $className */ + public static function illegalLifecycleCallbackOnEmbeddedClass(string $event, string $className): self + { + return new self(sprintf( + <<<'EXCEPTION' + Context: Attempt to register lifecycle callback "%s" on embedded class "%s". + Problem: Registering lifecycle callbacks on embedded classes is not allowed. + EXCEPTION, + $event, + $className, + )); + } + + public static function entityListenerClassNotFound(string $listenerName, string $className): self + { + return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className)); + } + + public static function entityListenerMethodNotFound(string $listenerName, string $methodName, string $className): self + { + return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName)); + } + + public static function duplicateEntityListener(string $listenerName, string $methodName, string $className): self + { + return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className)); + } + + /** @param class-string $className */ + public static function invalidFetchMode(string $className, string $fetchMode): self + { + return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $fetchMode . "'"); + } + + public static function invalidGeneratedMode(int|string $generatedMode): self + { + return new self("Invalid generated mode '" . $generatedMode . "'"); + } + + public static function compositeKeyAssignedIdGeneratorRequired(string $className): self + { + return new self("Entity '" . $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported."); + } + + public static function invalidTargetEntityClass(string $targetEntity, string $sourceEntity, string $associationName): self + { + return new self('The target-entity ' . $targetEntity . " cannot be found in '" . $sourceEntity . '#' . $associationName . "'."); + } + + /** @param string[] $cascades */ + public static function invalidCascadeOption(array $cascades, string $className, string $propertyName): self + { + $cascades = implode(', ', array_map(static fn (string $e): string => "'" . $e . "'", $cascades)); + + return new self(sprintf( + "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', and 'detach'", + $className, + $propertyName, + $cascades, + )); + } + + public static function missingSequenceName(string $className): self + { + return new self( + sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className), + ); + } + + public static function infiniteEmbeddableNesting(string $className, string $propertyName): self + { + return new self( + sprintf( + 'Infinite nesting detected for embedded property %s::%s. ' . + 'You cannot embed an embeddable from the same type inside an embeddable.', + $className, + $propertyName, + ), + ); + } + + public static function illegalOverrideOfInheritedProperty(string $className, string $propertyName, string $inheritFromClass): self + { + return new self( + sprintf( + 'Overrides are only allowed for fields or associations declared in mapped superclasses or traits. This is not the case for %s::%s, which was inherited from %s.', + $className, + $propertyName, + $inheritFromClass, + ), + ); + } + + public static function invalidIndexConfiguration(string $className, string $indexName): self + { + return new self( + sprintf( + 'Index %s for entity %s should contain columns or fields values, but not both.', + $indexName, + $className, + ), + ); + } + + public static function invalidUniqueConstraintConfiguration(string $className, string $indexName): self + { + return new self( + sprintf( + 'Unique constraint %s for entity %s should contain columns or fields values, but not both.', + $indexName, + $className, + ), + ); + } + + public static function invalidOverrideType(string $expectdType, mixed $givenValue): self + { + return new self(sprintf( + 'Expected %s, but %s was given.', + $expectdType, + get_debug_type($givenValue), + )); + } + + public static function backedEnumTypeRequired(string $className, string $fieldName, string $enumType): self + { + return new self(sprintf( + 'Attempting to map a non-backed enum type %s in entity %s::$%s. Please use backed enums only', + $enumType, + $className, + $fieldName, + )); + } + + public static function nonEnumTypeMapped(string $className, string $fieldName, string $enumType): self + { + return new self(sprintf( + 'Attempting to map non-enum type %s as enum in entity %s::$%s', + $enumType, + $className, + $fieldName, + )); + } + + /** + * @param class-string $className + * @param class-string $enumType + */ + public static function invalidEnumValue( + string $className, + string $fieldName, + string $value, + string $enumType, + ValueError $previous, + ): self { + return new self(sprintf( + <<<'EXCEPTION' +Context: Trying to hydrate enum property "%s::$%s" +Problem: Case "%s" is not listed in enum "%s" +Solution: Either add the case to the enum type or migrate the database column to use another case of the enum +EXCEPTION + , + $className, + $fieldName, + $value, + $enumType, + ), 0, $previous); + } + + /** @param LibXMLError[] $errors */ + public static function fromLibXmlErrors(array $errors): self + { + $formatter = static fn (LibXMLError $error): string => sprintf( + 'libxml error: %s in %s at line %d', + $error->message, + $error->file, + $error->line, + ); + + return new self(implode(PHP_EOL, array_map($formatter, $errors))); + } + + public static function invalidAttributeOnEmbeddable(string $entityName, string $attributeName): self + { + return new self(sprintf( + 'Attribute "%s" on embeddable "%s" is not allowed.', + $attributeName, + $entityName, + )); + } +} -- cgit v1.2.3