1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Cache\Cache as CacheDriver; |
23
|
|
|
use Doctrine\Persistence\ObjectRepository; |
24
|
|
|
use Exception; |
25
|
|
|
use function sprintf; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Base exception class for all ORM exceptions. |
29
|
|
|
* |
30
|
|
|
* @author Roman Borschel <[email protected]> |
31
|
|
|
* @since 2.0 |
32
|
|
|
*/ |
33
|
|
|
class ORMException extends Exception |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @return ORMException |
37
|
|
|
*/ |
38
|
|
|
public static function missingMappingDriverImpl() |
39
|
|
|
{ |
40
|
|
|
return new self("It's a requirement to specify a Metadata Driver and pass it ". |
41
|
|
|
"to Doctrine\\ORM\\Configuration::setMetadataDriverImpl()."); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $queryName |
46
|
|
|
* |
47
|
|
|
* @return ORMException |
48
|
|
|
*/ |
49
|
1 |
|
public static function namedQueryNotFound($queryName) |
50
|
|
|
{ |
51
|
1 |
|
return new self('Could not find a named query by the name "' . $queryName . '"'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $nativeQueryName |
56
|
|
|
* |
57
|
|
|
* @return ORMException |
58
|
|
|
*/ |
59
|
1 |
|
public static function namedNativeQueryNotFound($nativeQueryName) |
60
|
|
|
{ |
61
|
1 |
|
return new self('Could not find a named native query by the name "' . $nativeQueryName . '"'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param object $entity |
66
|
|
|
* @param object $relatedEntity |
67
|
|
|
* |
68
|
|
|
* @return ORMException |
69
|
|
|
*/ |
70
|
|
|
public static function entityMissingForeignAssignedId($entity, $relatedEntity) |
71
|
|
|
{ |
72
|
|
|
return new self( |
73
|
|
|
"Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " . |
74
|
|
|
"however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " . |
75
|
|
|
"and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " . |
76
|
|
|
"of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call " . |
77
|
|
|
"EntityManager#flush() between both persist operations." |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param object $entity |
83
|
|
|
* @param string $field |
84
|
|
|
* |
85
|
|
|
* @return ORMException |
86
|
|
|
*/ |
87
|
2 |
|
public static function entityMissingAssignedIdForField($entity, $field) |
88
|
|
|
{ |
89
|
2 |
|
return new self("Entity of type " . get_class($entity) . " is missing an assigned ID for field '" . $field . "'. " . |
90
|
2 |
|
"The identifier generation strategy for this entity requires the ID field to be populated before ". |
91
|
2 |
|
"EntityManager#persist() is called. If you want automatically generated identifiers instead " . |
92
|
2 |
|
"you need to adjust the metadata mapping accordingly." |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $field |
98
|
|
|
* |
99
|
|
|
* @return ORMException |
100
|
|
|
*/ |
101
|
3 |
|
public static function unrecognizedField($field) |
102
|
|
|
{ |
103
|
3 |
|
return new self("Unrecognized field: $field"); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* |
108
|
|
|
* @param string $class |
109
|
|
|
* @param string $association |
110
|
|
|
* @param string $given |
111
|
|
|
* @param string $expected |
112
|
|
|
* |
113
|
|
|
* @return \Doctrine\ORM\ORMInvalidArgumentException |
114
|
|
|
*/ |
115
|
|
|
public static function unexpectedAssociationValue($class, $association, $given, $expected) |
116
|
|
|
{ |
117
|
|
|
return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected)); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param string $className |
122
|
|
|
* @param string $field |
123
|
|
|
* |
124
|
|
|
* @return ORMException |
125
|
|
|
*/ |
126
|
1 |
|
public static function invalidOrientation($className, $field) |
127
|
|
|
{ |
128
|
1 |
|
return new self("Invalid order by orientation specified for " . $className . "#" . $field); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $mode |
133
|
|
|
* |
134
|
|
|
* @return ORMException |
135
|
|
|
*/ |
136
|
|
|
public static function invalidFlushMode($mode) |
137
|
|
|
{ |
138
|
|
|
return new self("'$mode' is an invalid flush mode."); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return ORMException |
143
|
|
|
*/ |
144
|
5 |
|
public static function entityManagerClosed() |
145
|
|
|
{ |
146
|
5 |
|
return new self("The EntityManager is closed."); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $mode |
151
|
|
|
* |
152
|
|
|
* @return ORMException |
153
|
|
|
*/ |
154
|
|
|
public static function invalidHydrationMode($mode) |
155
|
|
|
{ |
156
|
|
|
return new self("'$mode' is an invalid hydration mode."); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return ORMException |
161
|
|
|
*/ |
162
|
|
|
public static function mismatchedEventManager() |
163
|
|
|
{ |
164
|
|
|
return new self("Cannot use different EventManager instances for EntityManager and Connection."); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $methodName |
169
|
|
|
* |
170
|
|
|
* @return ORMException |
171
|
|
|
*/ |
172
|
1 |
|
public static function findByRequiresParameter($methodName) |
173
|
|
|
{ |
174
|
1 |
|
return new self("You need to pass a parameter to '".$methodName."'"); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $entityName |
179
|
|
|
* @param string $fieldName |
180
|
|
|
* @param string $method |
181
|
|
|
* |
182
|
|
|
* @return ORMException |
183
|
|
|
*/ |
184
|
|
|
public static function invalidFindByCall($entityName, $fieldName, $method) |
185
|
|
|
{ |
186
|
|
|
return new self( |
187
|
|
|
"Entity '".$entityName."' has no field '".$fieldName."'. ". |
188
|
|
|
"You can therefore not call '".$method."' on the entities' repository" |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param string $entityName |
194
|
|
|
* @param string $fieldName |
195
|
|
|
* @param string $method |
196
|
|
|
* |
197
|
|
|
* @return ORMException |
198
|
|
|
*/ |
199
|
1 |
|
public static function invalidMagicCall($entityName, $fieldName, $method) |
200
|
|
|
{ |
201
|
1 |
|
return new self( |
202
|
1 |
|
"Entity '".$entityName."' has no field '".$fieldName."'. ". |
203
|
1 |
|
"You can therefore not call '".$method."' on the entities' repository" |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string $entityName |
209
|
|
|
* @param string $associationFieldName |
210
|
|
|
* |
211
|
|
|
* @return ORMException |
212
|
|
|
*/ |
213
|
2 |
|
public static function invalidFindByInverseAssociation($entityName, $associationFieldName) |
214
|
|
|
{ |
215
|
2 |
|
return new self( |
216
|
2 |
|
"You cannot search for the association field '".$entityName."#".$associationFieldName."', ". |
217
|
2 |
|
"because it is the inverse side of an association. Find methods only work on owning side associations." |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return ORMException |
223
|
|
|
*/ |
224
|
|
|
public static function invalidResultCacheDriver() |
225
|
|
|
{ |
226
|
|
|
return new self("Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache."); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return ORMException |
231
|
|
|
*/ |
232
|
|
|
public static function notSupported() |
233
|
|
|
{ |
234
|
|
|
return new self("This behaviour is (currently) not supported by Doctrine 2"); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return ORMException |
239
|
|
|
*/ |
240
|
1 |
|
public static function queryCacheNotConfigured() |
241
|
|
|
{ |
242
|
1 |
|
return new self('Query Cache is not configured.'); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return ORMException |
247
|
|
|
*/ |
248
|
1 |
|
public static function metadataCacheNotConfigured() |
249
|
|
|
{ |
250
|
1 |
|
return new self('Class Metadata Cache is not configured.'); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache |
255
|
|
|
* |
256
|
|
|
* @return ORMException |
257
|
|
|
*/ |
258
|
1 |
|
public static function queryCacheUsesNonPersistentCache(CacheDriver $cache) |
259
|
|
|
{ |
260
|
1 |
|
return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.'); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache |
265
|
|
|
* |
266
|
|
|
* @return ORMException |
267
|
|
|
*/ |
268
|
1 |
|
public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache) |
269
|
|
|
{ |
270
|
1 |
|
return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.'); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return ORMException |
275
|
|
|
*/ |
276
|
3 |
|
public static function proxyClassesAlwaysRegenerating() |
277
|
|
|
{ |
278
|
3 |
|
return new self('Proxy Classes are always regenerating.'); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @param string $entityNamespaceAlias |
283
|
|
|
* |
284
|
|
|
* @return ORMException |
285
|
|
|
*/ |
286
|
1 |
|
public static function unknownEntityNamespace($entityNamespaceAlias) |
287
|
|
|
{ |
288
|
1 |
|
return new self( |
289
|
1 |
|
"Unknown Entity namespace alias '$entityNamespaceAlias'." |
290
|
|
|
); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param string $className |
295
|
|
|
* |
296
|
|
|
* @return ORMException |
297
|
|
|
*/ |
298
|
1 |
|
public static function invalidEntityRepository($className) |
299
|
|
|
{ |
300
|
1 |
|
return new self(sprintf( |
301
|
1 |
|
"Invalid repository class '%s'. It must be a %s.", |
302
|
1 |
|
$className, |
303
|
1 |
|
ObjectRepository::class |
304
|
|
|
)); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @param string $className |
309
|
|
|
* @param string $fieldName |
310
|
|
|
* |
311
|
|
|
* @return ORMException |
312
|
|
|
*/ |
313
|
1 |
|
public static function missingIdentifierField($className, $fieldName) |
314
|
|
|
{ |
315
|
1 |
|
return new self("The identifier $fieldName is missing for a query of " . $className); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param string $className |
320
|
|
|
* @param string[] $fieldNames |
321
|
|
|
* |
322
|
|
|
* @return ORMException |
323
|
|
|
*/ |
324
|
2 |
|
public static function unrecognizedIdentifierFields($className, $fieldNames) |
325
|
|
|
{ |
326
|
2 |
|
return new self( |
327
|
2 |
|
"Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " . |
328
|
2 |
|
"are not present on class '" . $className . "'." |
329
|
|
|
); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @return ORMException |
334
|
|
|
*/ |
335
|
1 |
|
public static function cantUseInOperatorOnCompositeKeys() |
336
|
|
|
{ |
337
|
1 |
|
return new self("Can't use IN operator on entities that have composite keys."); |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
|