diff options
Diffstat (limited to 'vendor/doctrine/orm/src/ORMInvalidArgumentException.php')
| -rw-r--r-- | vendor/doctrine/orm/src/ORMInvalidArgumentException.php | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/ORMInvalidArgumentException.php b/vendor/doctrine/orm/src/ORMInvalidArgumentException.php new file mode 100644 index 0000000..fe07a2a --- /dev/null +++ b/vendor/doctrine/orm/src/ORMInvalidArgumentException.php | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM; | ||
| 6 | |||
| 7 | use Doctrine\ORM\Mapping\AssociationMapping; | ||
| 8 | use Doctrine\ORM\Mapping\ClassMetadata; | ||
| 9 | use InvalidArgumentException; | ||
| 10 | use Stringable; | ||
| 11 | |||
| 12 | use function array_map; | ||
| 13 | use function count; | ||
| 14 | use function get_debug_type; | ||
| 15 | use function gettype; | ||
| 16 | use function implode; | ||
| 17 | use function is_scalar; | ||
| 18 | use function reset; | ||
| 19 | use function spl_object_id; | ||
| 20 | use function sprintf; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Contains exception messages for all invalid lifecycle state exceptions inside UnitOfWork | ||
| 24 | */ | ||
| 25 | class ORMInvalidArgumentException extends InvalidArgumentException | ||
| 26 | { | ||
| 27 | public static function scheduleInsertForManagedEntity(object $entity): self | ||
| 28 | { | ||
| 29 | return new self('A managed+dirty entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static function scheduleInsertForRemovedEntity(object $entity): self | ||
| 33 | { | ||
| 34 | return new self('Removed entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); | ||
| 35 | } | ||
| 36 | |||
| 37 | public static function scheduleInsertTwice(object $entity): self | ||
| 38 | { | ||
| 39 | return new self('Entity ' . self::objToStr($entity) . ' can not be scheduled for insertion twice.'); | ||
| 40 | } | ||
| 41 | |||
| 42 | public static function entityWithoutIdentity(string $className, object $entity): self | ||
| 43 | { | ||
| 44 | return new self( | ||
| 45 | "The given entity of type '" . $className . "' (" . self::objToStr($entity) . ') has no identity/no ' . | ||
| 46 | 'id values set. It cannot be added to the identity map.', | ||
| 47 | ); | ||
| 48 | } | ||
| 49 | |||
| 50 | public static function readOnlyRequiresManagedEntity(object $entity): self | ||
| 51 | { | ||
| 52 | return new self('Only managed entities can be marked or checked as read only. But ' . self::objToStr($entity) . ' is not'); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** @param non-empty-list<array{AssociationMapping, object}> $newEntitiesWithAssociations */ | ||
| 56 | public static function newEntitiesFoundThroughRelationships(array $newEntitiesWithAssociations): self | ||
| 57 | { | ||
| 58 | $errorMessages = array_map( | ||
| 59 | static function (array $newEntityWithAssociation): string { | ||
| 60 | [$associationMapping, $entity] = $newEntityWithAssociation; | ||
| 61 | |||
| 62 | return self::newEntityFoundThroughRelationshipMessage($associationMapping, $entity); | ||
| 63 | }, | ||
| 64 | $newEntitiesWithAssociations, | ||
| 65 | ); | ||
| 66 | |||
| 67 | if (count($errorMessages) === 1) { | ||
| 68 | return new self(reset($errorMessages)); | ||
| 69 | } | ||
| 70 | |||
| 71 | return new self( | ||
| 72 | 'Multiple non-persisted new entities were found through the given association graph:' | ||
| 73 | . "\n\n * " | ||
| 74 | . implode("\n * ", $errorMessages), | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | public static function newEntityFoundThroughRelationship(AssociationMapping $associationMapping, object $entry): self | ||
| 79 | { | ||
| 80 | return new self(self::newEntityFoundThroughRelationshipMessage($associationMapping, $entry)); | ||
| 81 | } | ||
| 82 | |||
| 83 | public static function detachedEntityFoundThroughRelationship(AssociationMapping $assoc, object $entry): self | ||
| 84 | { | ||
| 85 | return new self('A detached entity of type ' . $assoc->targetEntity . ' (' . self::objToStr($entry) . ') ' | ||
| 86 | . " was found through the relationship '" . $assoc->sourceEntity . '#' . $assoc->fieldName . "' " | ||
| 87 | . 'during cascading a persist operation.'); | ||
| 88 | } | ||
| 89 | |||
| 90 | public static function entityNotManaged(object $entity): self | ||
| 91 | { | ||
| 92 | return new self('Entity ' . self::objToStr($entity) . ' is not managed. An entity is managed if its fetched ' . | ||
| 93 | 'from the database or registered as new through EntityManager#persist'); | ||
| 94 | } | ||
| 95 | |||
| 96 | public static function entityHasNoIdentity(object $entity, string $operation): self | ||
| 97 | { | ||
| 98 | return new self('Entity has no identity, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); | ||
| 99 | } | ||
| 100 | |||
| 101 | public static function entityIsRemoved(object $entity, string $operation): self | ||
| 102 | { | ||
| 103 | return new self('Entity is removed, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); | ||
| 104 | } | ||
| 105 | |||
| 106 | public static function detachedEntityCannot(object $entity, string $operation): self | ||
| 107 | { | ||
| 108 | return new self('Detached entity ' . self::objToStr($entity) . ' cannot be ' . $operation); | ||
| 109 | } | ||
| 110 | |||
| 111 | public static function invalidObject(string $context, mixed $given, int $parameterIndex = 1): self | ||
| 112 | { | ||
| 113 | return new self($context . ' expects parameter ' . $parameterIndex . | ||
| 114 | ' to be an entity object, ' . gettype($given) . ' given.'); | ||
| 115 | } | ||
| 116 | |||
| 117 | public static function invalidCompositeIdentifier(): self | ||
| 118 | { | ||
| 119 | return new self('Binding an entity with a composite primary key to a query is not supported. ' . | ||
| 120 | 'You should split the parameter into the explicit fields and bind them separately.'); | ||
| 121 | } | ||
| 122 | |||
| 123 | public static function invalidIdentifierBindingEntity(string $class): self | ||
| 124 | { | ||
| 125 | return new self(sprintf( | ||
| 126 | <<<'EXCEPTION' | ||
| 127 | Binding entities to query parameters only allowed for entities that have an identifier. | ||
| 128 | Class "%s" does not have an identifier. | ||
| 129 | EXCEPTION | ||
| 130 | , | ||
| 131 | $class, | ||
| 132 | )); | ||
| 133 | } | ||
| 134 | |||
| 135 | public static function invalidAssociation(ClassMetadata $targetClass, AssociationMapping $assoc, mixed $actualValue): self | ||
| 136 | { | ||
| 137 | $expectedType = $targetClass->getName(); | ||
| 138 | |||
| 139 | return new self(sprintf( | ||
| 140 | 'Expected value of type "%s" for association field "%s#$%s", got "%s" instead.', | ||
| 141 | $expectedType, | ||
| 142 | $assoc->sourceEntity, | ||
| 143 | $assoc->fieldName, | ||
| 144 | get_debug_type($actualValue), | ||
| 145 | )); | ||
| 146 | } | ||
| 147 | |||
| 148 | public static function invalidAutoGenerateMode(mixed $value): self | ||
| 149 | { | ||
| 150 | return new self(sprintf('Invalid auto generate mode "%s" given.', is_scalar($value) ? (string) $value : get_debug_type($value))); | ||
| 151 | } | ||
| 152 | |||
| 153 | public static function missingPrimaryKeyValue(string $className, string $idField): self | ||
| 154 | { | ||
| 155 | return new self(sprintf('Missing value for primary key %s on %s', $idField, $className)); | ||
| 156 | } | ||
| 157 | |||
| 158 | public static function proxyDirectoryRequired(): self | ||
| 159 | { | ||
| 160 | return new self('You must configure a proxy directory. See docs for details'); | ||
| 161 | } | ||
| 162 | |||
| 163 | public static function proxyNamespaceRequired(): self | ||
| 164 | { | ||
| 165 | return new self('You must configure a proxy namespace'); | ||
| 166 | } | ||
| 167 | |||
| 168 | public static function proxyDirectoryNotWritable(string $proxyDirectory): self | ||
| 169 | { | ||
| 170 | return new self(sprintf('Your proxy directory "%s" must be writable', $proxyDirectory)); | ||
| 171 | } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * Helper method to show an object as string. | ||
| 175 | */ | ||
| 176 | private static function objToStr(object $obj): string | ||
| 177 | { | ||
| 178 | return $obj instanceof Stringable ? (string) $obj : get_debug_type($obj) . '@' . spl_object_id($obj); | ||
| 179 | } | ||
| 180 | |||
| 181 | private static function newEntityFoundThroughRelationshipMessage(AssociationMapping $associationMapping, object $entity): string | ||
| 182 | { | ||
| 183 | return 'A new entity was found through the relationship \'' | ||
| 184 | . $associationMapping->sourceEntity . '#' . $associationMapping->fieldName . '\' that was not' | ||
| 185 | . ' configured to cascade persist operations for entity: ' . self::objToStr($entity) . '.' | ||
| 186 | . ' To solve this issue: Either explicitly call EntityManager#persist()' | ||
| 187 | . ' on this unknown entity or configure cascade persist' | ||
| 188 | . ' this association in the mapping for example @ManyToOne(..,cascade={"persist"}).' | ||
| 189 | . ($entity instanceof Stringable | ||
| 190 | ? '' | ||
| 191 | : ' If you cannot find out which entity causes the problem implement \'' | ||
| 192 | . $associationMapping->targetEntity . '#__toString()\' to get a clue.' | ||
| 193 | ); | ||
| 194 | } | ||
| 195 | } | ||
