1 | <?php |
||
28 | class ORMInvalidArgumentException extends \InvalidArgumentException |
||
29 | { |
||
30 | /** |
||
31 | * @param object $entity |
||
32 | * |
||
33 | * @return ORMInvalidArgumentException |
||
34 | */ |
||
35 | 1 | static public function scheduleInsertForManagedEntity($entity) |
|
39 | |||
40 | /** |
||
41 | * @param object $entity |
||
42 | * |
||
43 | * @return ORMInvalidArgumentException |
||
44 | */ |
||
45 | 1 | static public function scheduleInsertForRemovedEntity($entity) |
|
49 | |||
50 | /** |
||
51 | * @param object $entity |
||
52 | * |
||
53 | * @return ORMInvalidArgumentException |
||
54 | */ |
||
55 | 1 | static public function scheduleInsertTwice($entity) |
|
59 | |||
60 | /** |
||
61 | * @param string $className |
||
62 | * @param object $entity |
||
63 | * |
||
64 | * @return ORMInvalidArgumentException |
||
65 | */ |
||
66 | 6 | static public function entityWithoutIdentity($className, $entity) |
|
73 | |||
74 | /** |
||
75 | * @param object $entity |
||
76 | * |
||
77 | * @return ORMInvalidArgumentException |
||
78 | */ |
||
79 | 1 | static public function readOnlyRequiresManagedEntity($entity) |
|
83 | |||
84 | /** |
||
85 | * @param array $assoc |
||
86 | * @param object $entry |
||
87 | * |
||
88 | * @return ORMInvalidArgumentException |
||
89 | */ |
||
90 | 4 | static public function newEntityFoundThroughRelationship(array $assoc, $entry) |
|
91 | { |
||
92 | 4 | return new self("A new entity was found through the relationship '" |
|
93 | 4 | . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' that was not" |
|
94 | 4 | . " configured to cascade persist operations for entity: " . self::objToStr($entry) . "." |
|
95 | . " To solve this issue: Either explicitly call EntityManager#persist()" |
||
96 | . " on this unknown entity or configure cascade persist " |
||
97 | 4 | . " this association in the mapping for example @ManyToOne(..,cascade={\"persist\"})." |
|
98 | 4 | . (method_exists($entry, '__toString') ? "": " If you cannot find out which entity causes the problem" |
|
99 | 4 | . " implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue.")); |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param array $assoc |
||
104 | * @param object $entry |
||
105 | * |
||
106 | * @return ORMInvalidArgumentException |
||
107 | */ |
||
108 | static public function detachedEntityFoundThroughRelationship(array $assoc, $entry) |
||
109 | { |
||
110 | return new self("A detached entity of type " . $assoc['targetEntity'] . " (" . self::objToStr($entry) . ") " |
||
111 | . " was found through the relationship '" . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' " |
||
112 | . "during cascading a persist operation."); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @param object $entity |
||
117 | * |
||
118 | * @return ORMInvalidArgumentException |
||
119 | */ |
||
120 | 1 | static public function entityNotManaged($entity) |
|
121 | { |
||
122 | 1 | return new self("Entity " . self::objToStr($entity) . " is not managed. An entity is managed if its fetched " . |
|
123 | 1 | "from the database or registered as new through EntityManager#persist"); |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * @param object $entity |
||
128 | * @param string $operation |
||
129 | * |
||
130 | * @return ORMInvalidArgumentException |
||
131 | */ |
||
132 | static public function entityHasNoIdentity($entity, $operation) |
||
136 | |||
137 | /** |
||
138 | * @param object $entity |
||
139 | * @param string $operation |
||
140 | * |
||
141 | * @return ORMInvalidArgumentException |
||
142 | */ |
||
143 | static public function entityIsRemoved($entity, $operation) |
||
147 | |||
148 | /** |
||
149 | * @param object $entity |
||
150 | * @param string $operation |
||
151 | * |
||
152 | * @return ORMInvalidArgumentException |
||
153 | */ |
||
154 | static public function detachedEntityCannot($entity, $operation) |
||
158 | |||
159 | /** |
||
160 | * @param string $context |
||
161 | * @param mixed $given |
||
162 | * @param int $parameterIndex |
||
163 | * |
||
164 | * @return ORMInvalidArgumentException |
||
165 | */ |
||
166 | 5 | public static function invalidObject($context, $given, $parameterIndex = 1) |
|
167 | { |
||
168 | 5 | return new self($context . ' expects parameter ' . $parameterIndex . |
|
169 | 5 | ' to be an entity object, '. gettype($given) . ' given.'); |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * @return ORMInvalidArgumentException |
||
174 | */ |
||
175 | public static function invalidCompositeIdentifier() |
||
180 | |||
181 | /** |
||
182 | * @return ORMInvalidArgumentException |
||
183 | */ |
||
184 | 1 | public static function invalidIdentifierBindingEntity() |
|
188 | |||
189 | /** |
||
190 | * @param ClassMetadata $targetClass |
||
191 | * @param array $assoc |
||
192 | * @param mixed $actualValue |
||
193 | * |
||
194 | * @return self |
||
195 | */ |
||
196 | 13 | public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue) |
|
197 | { |
||
198 | 13 | $expectedType = 'Doctrine\Common\Collections\Collection|array'; |
|
199 | |||
200 | 13 | if (($assoc['type'] & ClassMetadata::TO_ONE) > 0) { |
|
201 | 13 | $expectedType = $targetClass->getName(); |
|
202 | } |
||
203 | |||
204 | 13 | return new self(sprintf( |
|
205 | 13 | 'Expected value of type "%s" for association field "%s#$%s", got "%s" instead.', |
|
206 | 13 | $expectedType, |
|
207 | 13 | $assoc['sourceEntity'], |
|
208 | 13 | $assoc['fieldName'], |
|
209 | 13 | is_object($actualValue) ? get_class($actualValue) : gettype($actualValue) |
|
210 | )); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Used when a given entityName hasn't the good type |
||
215 | * |
||
216 | * @param mixed $entityName The given entity (which shouldn't be a string) |
||
217 | * |
||
218 | * @return self |
||
219 | */ |
||
220 | 6 | public static function invalidEntityName($entityName) |
|
224 | |||
225 | /** |
||
226 | * Helper method to show an object as string. |
||
227 | * |
||
228 | * @param object $obj |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | 15 | private static function objToStr($obj) |
|
236 | } |
||
237 |