Cache
9 months ago
Decorator
9 months ago
Event
9 months ago
Exception
9 months ago
Id
9 months ago
Internal
9 months ago
Mapping
9 months ago
Persisters
8 months ago
Proxy
9 months ago
Query
9 months ago
Repository
9 months ago
Tools
9 months ago
Utility
9 months ago
AbstractQuery.php
9 months ago
Cache.php
9 months ago
Configuration.php
9 months ago
EntityManager.php
9 months ago
EntityManagerInterface.php
9 months ago
EntityNotFoundException.php
9 months ago
EntityRepository.php
9 months ago
Events.php
9 months ago
LazyCriteriaCollection.php
9 months ago
NativeQuery.php
9 months ago
NoResultException.php
9 months ago
NonUniqueResultException.php
9 months ago
ORMException.php
9 months ago
ORMInvalidArgumentException.php
9 months ago
ORMSetup.php
9 months ago
OptimisticLockException.php
9 months ago
PersistentCollection.php
9 months ago
PessimisticLockException.php
9 months ago
Query.php
9 months ago
QueryBuilder.php
9 months ago
TransactionRequiredException.php
9 months ago
UnexpectedResultException.php
9 months ago
UnitOfWork.php
9 months ago
Version.php
9 months ago
index.php
9 months ago
ORMInvalidArgumentException.php
136 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 6 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata; |
| 7 | use InvalidArgumentException; |
| 8 | use function array_map; |
| 9 | use function count; |
| 10 | use function func_get_arg; |
| 11 | use function func_num_args; |
| 12 | use function get_debug_type; |
| 13 | use function gettype; |
| 14 | use function implode; |
| 15 | use function is_scalar; |
| 16 | use function method_exists; |
| 17 | use function reset; |
| 18 | use function spl_object_id; |
| 19 | use function sprintf; |
| 20 | class ORMInvalidArgumentException extends InvalidArgumentException |
| 21 | { |
| 22 | public static function scheduleInsertForManagedEntity($entity) |
| 23 | { |
| 24 | return new self('A managed+dirty entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); |
| 25 | } |
| 26 | public static function scheduleInsertForRemovedEntity($entity) |
| 27 | { |
| 28 | return new self('Removed entity ' . self::objToStr($entity) . ' can not be scheduled for insertion.'); |
| 29 | } |
| 30 | public static function scheduleInsertTwice($entity) |
| 31 | { |
| 32 | return new self('Entity ' . self::objToStr($entity) . ' can not be scheduled for insertion twice.'); |
| 33 | } |
| 34 | public static function entityWithoutIdentity($className, $entity) |
| 35 | { |
| 36 | return new self("The given entity of type '" . $className . "' (" . self::objToStr($entity) . ') has no identity/no ' . 'id values set. It cannot be added to the identity map.'); |
| 37 | } |
| 38 | public static function readOnlyRequiresManagedEntity($entity) |
| 39 | { |
| 40 | return new self('Only managed entities can be marked or checked as read only. But ' . self::objToStr($entity) . ' is not'); |
| 41 | } |
| 42 | public static function newEntitiesFoundThroughRelationships($newEntitiesWithAssociations) |
| 43 | { |
| 44 | $errorMessages = array_map(static function (array $newEntityWithAssociation) : string { |
| 45 | [$associationMapping, $entity] = $newEntityWithAssociation; |
| 46 | return self::newEntityFoundThroughRelationshipMessage($associationMapping, $entity); |
| 47 | }, $newEntitiesWithAssociations); |
| 48 | if (count($errorMessages) === 1) { |
| 49 | return new self(reset($errorMessages)); |
| 50 | } |
| 51 | return new self('Multiple non-persisted new entities were found through the given association graph:' . "\n\n * " . implode("\n * ", $errorMessages)); |
| 52 | } |
| 53 | public static function newEntityFoundThroughRelationship(array $associationMapping, $entry) |
| 54 | { |
| 55 | return new self(self::newEntityFoundThroughRelationshipMessage($associationMapping, $entry)); |
| 56 | } |
| 57 | public static function detachedEntityFoundThroughRelationship(array $assoc, $entry) |
| 58 | { |
| 59 | return new self('A detached entity of type ' . $assoc['targetEntity'] . ' (' . self::objToStr($entry) . ') ' . " was found through the relationship '" . $assoc['sourceEntity'] . '#' . $assoc['fieldName'] . "' " . 'during cascading a persist operation.'); |
| 60 | } |
| 61 | public static function entityNotManaged($entity) |
| 62 | { |
| 63 | return new self('Entity ' . self::objToStr($entity) . ' is not managed. An entity is managed if its fetched ' . 'from the database or registered as new through EntityManager#persist'); |
| 64 | } |
| 65 | public static function entityHasNoIdentity($entity, $operation) |
| 66 | { |
| 67 | return new self('Entity has no identity, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); |
| 68 | } |
| 69 | public static function entityIsRemoved($entity, $operation) |
| 70 | { |
| 71 | return new self('Entity is removed, therefore ' . $operation . ' cannot be performed. ' . self::objToStr($entity)); |
| 72 | } |
| 73 | public static function detachedEntityCannot($entity, $operation) |
| 74 | { |
| 75 | return new self('Detached entity ' . self::objToStr($entity) . ' cannot be ' . $operation); |
| 76 | } |
| 77 | public static function invalidObject($context, $given, $parameterIndex = 1) |
| 78 | { |
| 79 | return new self($context . ' expects parameter ' . $parameterIndex . ' to be an entity object, ' . gettype($given) . ' given.'); |
| 80 | } |
| 81 | public static function invalidCompositeIdentifier() |
| 82 | { |
| 83 | return new self('Binding an entity with a composite primary key to a query is not supported. ' . 'You should split the parameter into the explicit fields and bind them separately.'); |
| 84 | } |
| 85 | public static function invalidIdentifierBindingEntity() |
| 86 | { |
| 87 | if (func_num_args() === 0) { |
| 88 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/pull/9642', 'Omitting the class name in the exception method %s is deprecated.', __METHOD__); |
| 89 | return new self('Binding entities to query parameters only allowed for entities that have an identifier.'); |
| 90 | } |
| 91 | return new self(sprintf(<<<'EXCEPTION' |
| 92 | Binding entities to query parameters only allowed for entities that have an identifier. |
| 93 | Class "%s" does not have an identifier. |
| 94 | EXCEPTION |
| 95 | , func_get_arg(0))); |
| 96 | } |
| 97 | public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue) |
| 98 | { |
| 99 | $expectedType = $targetClass->getName(); |
| 100 | return new self(sprintf('Expected value of type "%s" for association field "%s#$%s", got "%s" instead.', $expectedType, $assoc['sourceEntity'], $assoc['fieldName'], get_debug_type($actualValue))); |
| 101 | } |
| 102 | public static function invalidEntityName($entityName) |
| 103 | { |
| 104 | Deprecation::triggerIfCalledFromOutside('doctrine/orm', 'https://github.com/doctrine/orm/pull/9471', '%s() is deprecated', __METHOD__); |
| 105 | return new self(sprintf('Entity name must be a string, %s given', get_debug_type($entityName))); |
| 106 | } |
| 107 | public static function invalidAutoGenerateMode($value) : self |
| 108 | { |
| 109 | return new self(sprintf('Invalid auto generate mode "%s" given.', is_scalar($value) ? (string) $value : get_debug_type($value))); |
| 110 | } |
| 111 | public static function missingPrimaryKeyValue(string $className, string $idField) : self |
| 112 | { |
| 113 | return new self(sprintf('Missing value for primary key %s on %s', $idField, $className)); |
| 114 | } |
| 115 | public static function proxyDirectoryRequired() : self |
| 116 | { |
| 117 | return new self('You must configure a proxy directory. See docs for details'); |
| 118 | } |
| 119 | public static function proxyNamespaceRequired() : self |
| 120 | { |
| 121 | return new self('You must configure a proxy namespace'); |
| 122 | } |
| 123 | public static function proxyDirectoryNotWritable(string $proxyDirectory) : self |
| 124 | { |
| 125 | return new self(sprintf('Your proxy directory "%s" must be writable', $proxyDirectory)); |
| 126 | } |
| 127 | private static function objToStr($obj) : string |
| 128 | { |
| 129 | return method_exists($obj, '__toString') ? (string) $obj : get_debug_type($obj) . '@' . spl_object_id($obj); |
| 130 | } |
| 131 | private static function newEntityFoundThroughRelationshipMessage(array $associationMapping, $entity) : string |
| 132 | { |
| 133 | return 'A new entity was found through the relationship \'' . $associationMapping['sourceEntity'] . '#' . $associationMapping['fieldName'] . '\' that was not' . ' configured to cascade persist operations for entity: ' . self::objToStr($entity) . '.' . ' To solve this issue: Either explicitly call EntityManager#persist()' . ' on this unknown entity or configure cascade persist' . ' this association in the mapping for example #[ORM\\ManyToOne(..., cascade: [\'persist\'])].' . (method_exists($entity, '__toString') ? '' : ' If you cannot find out which entity causes the problem implement \'' . $associationMapping['targetEntity'] . '#__toString()\' to get a clue.'); |
| 134 | } |
| 135 | } |
| 136 |