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