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