|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ODM\MongoDB\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Collection; |
|
8
|
|
|
use Doctrine\Common\Persistence\Mapping\MappingException as BaseMappingException; |
|
9
|
|
|
use function sprintf; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class for all exceptions related to the Doctrine MongoDB ODM |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
class MappingException extends BaseMappingException |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $name |
|
19
|
|
|
* @return MappingException |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function typeExists($name) |
|
22
|
|
|
{ |
|
23
|
|
|
return new self(sprintf('Type %s already exists.', $name)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $name |
|
28
|
|
|
* @return MappingException |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function typeNotFound($name) |
|
31
|
|
|
{ |
|
32
|
|
|
return new self(sprintf('Type to be overwritten %s does not exist.', $name)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $className |
|
37
|
|
|
* @param string $fieldName |
|
38
|
|
|
* @return MappingException |
|
39
|
|
|
*/ |
|
40
|
6 |
|
public static function mappingNotFound($className, $fieldName) |
|
41
|
|
|
{ |
|
42
|
6 |
|
return new self(sprintf("No mapping found for field '%s' in class '%s'.", $fieldName, $className)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $className |
|
47
|
|
|
* @param string $fieldName |
|
48
|
|
|
* @return MappingException |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function referenceMappingNotFound($className, $fieldName) |
|
51
|
|
|
{ |
|
52
|
|
|
return new self(sprintf("No reference mapping found for field '%s' in class '%s'.", $fieldName, $className)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $className |
|
57
|
|
|
* @param string $fieldName |
|
58
|
|
|
* @return MappingException |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public static function mappingNotFoundInClassNorDescendants($className, $fieldName) |
|
61
|
|
|
{ |
|
62
|
2 |
|
return new self(sprintf("No mapping found for field '%s' in class '%s' nor its descendants.", $fieldName, $className)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $fieldName |
|
67
|
|
|
* @param string $className |
|
68
|
|
|
* @param string $className2 |
|
69
|
|
|
* @return MappingException |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public static function referenceFieldConflict($fieldName, $className, $className2) |
|
72
|
|
|
{ |
|
73
|
2 |
|
return new self(sprintf("Reference mapping for field '%s' in class '%s' conflicts with one mapped in class '%s'.", $fieldName, $className, $className2)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $className |
|
78
|
|
|
* @param string $dbFieldName |
|
79
|
|
|
* @return MappingException |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function mappingNotFoundByDbName($className, $dbFieldName) |
|
82
|
|
|
{ |
|
83
|
|
|
return new self(sprintf("No mapping found for field by DB name '%s' in class '%s'.", $dbFieldName, $className)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $document |
|
88
|
|
|
* @param string $fieldName |
|
89
|
|
|
* @return MappingException |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function duplicateFieldMapping($document, $fieldName) |
|
92
|
|
|
{ |
|
93
|
|
|
return new self(sprintf('Property "%s" in "%s" was already declared, but it must be declared only once', $fieldName, $document)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $document |
|
98
|
|
|
* @param string $fieldName |
|
99
|
|
|
* @return MappingException |
|
100
|
|
|
*/ |
|
101
|
2 |
|
public static function discriminatorFieldConflict($document, $fieldName) |
|
102
|
|
|
{ |
|
103
|
2 |
|
return new self(sprintf('Discriminator field "%s" in "%s" conflicts with a mapped field\'s "name" attribute.', $fieldName, $document)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Throws an exception that indicates that a class used in a discriminator map does not exist. |
|
108
|
|
|
* An example would be an outdated (maybe renamed) classname. |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $className The class that could not be found |
|
111
|
|
|
* @param string $owningClass The class that declares the discriminator map. |
|
112
|
|
|
* @return MappingException |
|
113
|
|
|
*/ |
|
114
|
|
|
public static function invalidClassInDiscriminatorMap($className, $owningClass) |
|
115
|
|
|
{ |
|
116
|
|
|
return new self(sprintf("Document class '%s' used in the discriminator map of class '%s' does not exist.", $className, $owningClass)); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Throws an exception that indicates a discriminator value does not exist in a map |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $value The discriminator value that could not be found |
|
123
|
|
|
* @param string $owningClass The class that declares the discriminator map |
|
124
|
|
|
* @return MappingException |
|
125
|
|
|
*/ |
|
126
|
|
|
public static function invalidDiscriminatorValue($value, $owningClass) |
|
127
|
|
|
{ |
|
128
|
|
|
return new self(sprintf("Discriminator value '%s' used in the declaration of class '%s' does not exist.", $value, $owningClass)); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param string $className |
|
133
|
|
|
* @return MappingException |
|
134
|
|
|
*/ |
|
135
|
|
|
public static function missingFieldName($className) |
|
136
|
|
|
{ |
|
137
|
|
|
return new self(sprintf("The Document class '%s' field mapping misses the 'fieldName' attribute.", $className)); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param string $className |
|
142
|
|
|
* @return MappingException |
|
143
|
|
|
*/ |
|
144
|
3 |
|
public static function classIsNotAValidDocument($className) |
|
145
|
|
|
{ |
|
146
|
3 |
|
return new self(sprintf('Class %s is not a valid document or mapped super class.', $className)); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Exception for reflection exceptions - adds the document name, |
|
151
|
|
|
* because there might be long classnames that will be shortened |
|
152
|
|
|
* within the stacktrace |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $document The document's name |
|
155
|
|
|
* @return \Doctrine\ODM\MongoDB\Mapping\MappingException |
|
156
|
|
|
*/ |
|
157
|
|
|
public static function reflectionFailure($document, \ReflectionException $previousException) |
|
158
|
|
|
{ |
|
159
|
|
|
return new self('An error occurred in ' . $document, 0, $previousException); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @param string $documentName |
|
164
|
|
|
* @return MappingException |
|
165
|
|
|
*/ |
|
166
|
|
|
public static function identifierRequired($documentName) |
|
167
|
|
|
{ |
|
168
|
|
|
return new self(sprintf("No identifier/primary key specified for Document '%s'. Every Document must have an identifier/primary key.", $documentName)); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param string $className |
|
173
|
|
|
* @param string $fieldName |
|
174
|
|
|
* @return MappingException |
|
175
|
|
|
*/ |
|
176
|
|
|
public static function missingIdentifierField($className, $fieldName) |
|
177
|
|
|
{ |
|
178
|
|
|
return new self(sprintf('The identifier %s is missing for a query of %s', $fieldName, $className)); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param string $className |
|
183
|
|
|
* @return MappingException |
|
184
|
|
|
*/ |
|
185
|
|
|
public static function missingIdGeneratorClass($className) |
|
186
|
|
|
{ |
|
187
|
|
|
return new self(sprintf('The class-option for the custom ID generator is missing in class %s.', $className)); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param string $className |
|
192
|
|
|
* @return MappingException |
|
193
|
|
|
*/ |
|
194
|
|
|
public static function classIsNotAValidGenerator($className) |
|
195
|
|
|
{ |
|
196
|
|
|
return new self(sprintf('The class %s if not a valid ID generator of type AbstractIdGenerator.', $className)); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param string $className |
|
201
|
|
|
* @param string $optionName |
|
202
|
|
|
* @return MappingException |
|
203
|
|
|
*/ |
|
204
|
|
|
public static function missingGeneratorSetter($className, $optionName) |
|
205
|
|
|
{ |
|
206
|
|
|
return new self(sprintf('The class %s is missing a setter for the option %s.', $className, $optionName)); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @param string $className |
|
211
|
|
|
* @param string $fieldName |
|
212
|
|
|
* @return MappingException |
|
213
|
|
|
*/ |
|
214
|
1 |
|
public static function cascadeOnEmbeddedNotAllowed($className, $fieldName) |
|
215
|
|
|
{ |
|
216
|
1 |
|
return new self(sprintf('Cascade on %s::%s is not allowed.', $className, $fieldName)); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param string $className |
|
221
|
|
|
* @param string $fieldName |
|
222
|
|
|
* @return MappingException |
|
223
|
|
|
*/ |
|
224
|
3 |
|
public static function simpleReferenceRequiresTargetDocument($className, $fieldName) |
|
225
|
|
|
{ |
|
226
|
3 |
|
return new self(sprintf('Target document must be specified for simple reference: %s::%s', $className, $fieldName)); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @param string $targetDocument |
|
231
|
|
|
* @return MappingException |
|
232
|
|
|
*/ |
|
233
|
1 |
|
public static function simpleReferenceMustNotTargetDiscriminatedDocument($targetDocument) |
|
234
|
|
|
{ |
|
235
|
1 |
|
return new self(sprintf('Simple reference must not target document using Single Collection Inheritance, %s targeted.', $targetDocument)); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param string $strategy |
|
240
|
|
|
* @param string $className |
|
241
|
|
|
* @param string $fieldName |
|
242
|
|
|
* @return MappingException |
|
243
|
|
|
*/ |
|
244
|
1 |
|
public static function atomicCollectionStrategyNotAllowed($strategy, $className, $fieldName) |
|
245
|
|
|
{ |
|
246
|
1 |
|
return new self(sprintf('%s collection strategy can be used only in top level document, used in %s::%s', $strategy, $className, $fieldName)); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @param string $className |
|
251
|
|
|
* @param string $fieldName |
|
252
|
|
|
* @return MappingException |
|
253
|
|
|
*/ |
|
254
|
4 |
|
public static function owningAndInverseReferencesRequireTargetDocument($className, $fieldName) |
|
255
|
|
|
{ |
|
256
|
4 |
|
return new self(sprintf('Target document must be specified for owning/inverse sides of reference: %s::%s', $className, $fieldName)); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param string $className |
|
261
|
|
|
* @param string $fieldName |
|
262
|
|
|
* @return MappingException |
|
263
|
|
|
*/ |
|
264
|
1 |
|
public static function mustNotChangeIdentifierFieldsType($className, $fieldName) |
|
265
|
|
|
{ |
|
266
|
1 |
|
return new self(sprintf('%s::%s was declared an identifier and must stay this way.', $className, $fieldName)); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @param string $className |
|
271
|
|
|
* @param string $fieldName |
|
272
|
|
|
* @param string $strategy |
|
273
|
|
|
* @return MappingException |
|
274
|
|
|
*/ |
|
275
|
1 |
|
public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($className, $fieldName, $strategy) |
|
276
|
|
|
{ |
|
277
|
1 |
|
return new self(sprintf("ReferenceMany's sort can not be used with addToSet and pushAll strategies, %s used in %s::%s", $strategy, $className, $fieldName)); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @param string $className |
|
282
|
|
|
* @param string $fieldName |
|
283
|
|
|
* @param string $type |
|
284
|
|
|
* @param string $strategy |
|
285
|
|
|
* @return MappingException |
|
286
|
|
|
*/ |
|
287
|
|
|
public static function invalidStorageStrategy($className, $fieldName, $type, $strategy) |
|
288
|
|
|
{ |
|
289
|
|
|
return new self(sprintf('Invalid strategy %s used in %s::%s with type %s', $strategy, $className, $fieldName, $type)); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @param string $className |
|
294
|
|
|
* @param string $fieldName |
|
295
|
|
|
* @param string $collectionClass |
|
296
|
|
|
* @return MappingException |
|
297
|
|
|
*/ |
|
298
|
1 |
|
public static function collectionClassDoesNotImplementCommonInterface($className, $fieldName, $collectionClass) |
|
299
|
|
|
{ |
|
300
|
1 |
|
return new self(sprintf('%s used as custom collection class for %s::%s has to implement %s interface.', $collectionClass, $className, $fieldName, Collection::class)); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @param string $subclassName |
|
305
|
|
|
* @return MappingException |
|
306
|
|
|
*/ |
|
307
|
2 |
|
public static function shardKeyInSingleCollInheritanceSubclass($subclassName) |
|
308
|
|
|
{ |
|
309
|
2 |
|
return new self(sprintf('Shard key overriding in subclass is forbidden for single collection inheritance: %s', $subclassName)); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* @param string $className |
|
314
|
|
|
* @return MappingException |
|
315
|
|
|
*/ |
|
316
|
2 |
|
public static function embeddedDocumentCantHaveShardKey($className) |
|
317
|
|
|
{ |
|
318
|
2 |
|
return new self(sprintf("Embedded document can't have shard key: %s", $className)); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* @param string $className |
|
323
|
|
|
* @param string $fieldName |
|
324
|
|
|
* @return MappingException |
|
325
|
|
|
*/ |
|
326
|
1 |
|
public static function onlySetStrategyAllowedInShardKey($className, $fieldName) |
|
327
|
|
|
{ |
|
328
|
1 |
|
return new self(sprintf('Only fields using the SET strategy can be used in the shard key: %s::%s', $className, $fieldName)); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* @param string $className |
|
333
|
|
|
* @param string $fieldName |
|
334
|
|
|
* @return MappingException |
|
335
|
|
|
*/ |
|
336
|
3 |
|
public static function noMultiKeyShardKeys($className, $fieldName) |
|
337
|
|
|
{ |
|
338
|
3 |
|
return new self(sprintf('No multikey indexes are allowed in the shard key: %s::%s', $className, $fieldName)); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* @param string $className |
|
343
|
|
|
* @param string $fieldName |
|
344
|
|
|
* @return MappingException |
|
345
|
|
|
*/ |
|
346
|
|
|
public static function cannotLookupDbRefReference($className, $fieldName) |
|
347
|
|
|
{ |
|
348
|
|
|
return new self(sprintf("Cannot use reference '%s' in class '%s' for lookup or graphLookup: dbRef references are not supported.", $fieldName, $className)); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @param string $className |
|
353
|
|
|
* @param string $fieldName |
|
354
|
|
|
* @return MappingException |
|
355
|
|
|
*/ |
|
356
|
|
|
public static function repositoryMethodLookupNotAllowed($className, $fieldName) |
|
357
|
|
|
{ |
|
358
|
|
|
return new self(sprintf("Cannot use reference '%s' in class '%s' for lookup or graphLookup. repositoryMethod is not supported in \$lookup and \$graphLookup stages.", $fieldName, $className)); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* @param string $className |
|
363
|
|
|
* @return MappingException |
|
364
|
|
|
*/ |
|
365
|
1 |
|
public static function cannotUseShardedCollectionInOutStage($className) |
|
366
|
|
|
{ |
|
367
|
1 |
|
return new self(sprintf("Cannot use class '%s' as collection for out stage. Sharded collections are not allowed.", $className)); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* @param string $className |
|
372
|
|
|
* @return MappingException |
|
373
|
|
|
*/ |
|
374
|
3 |
|
public static function cannotUseShardedCollectionInLookupStages($className) |
|
375
|
|
|
{ |
|
376
|
3 |
|
return new self(sprintf("Cannot use class '%s' as collection for lookup or graphLookup stage. Sharded collections are not allowed.", $className)); |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @param string $className |
|
381
|
|
|
* @param string $fieldName |
|
382
|
|
|
* |
|
383
|
|
|
* @return MappingException |
|
384
|
|
|
*/ |
|
385
|
|
|
public static function referencePrimersOnlySupportedForInverseReferenceMany($className, $fieldName) |
|
386
|
|
|
{ |
|
387
|
|
|
return new self(sprintf("Cannot use reference priming on '%s' in class '%s'. Reference priming is only supported for inverse references", $fieldName, $className)); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
1 |
|
public static function connectFromFieldMustReferenceSameDocument($fieldName) |
|
391
|
|
|
{ |
|
392
|
1 |
|
return new self(sprintf("Cannot use field '%s' as connectFromField in a \$graphLookup stage. Reference must target the document itself.", $fieldName)); |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
3 |
|
public static function repositoryMethodCanNotBeCombinedWithSkipLimitAndSort($className, $fieldName) |
|
396
|
|
|
{ |
|
397
|
3 |
|
return new self(sprintf("'repositoryMethod' used on '%s' in class '%s' can not be combined with skip, limit or sort.", $fieldName, $className)); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
1 |
|
public static function fieldNotAllowedForGridFS($className, $fieldName) |
|
401
|
|
|
{ |
|
402
|
1 |
|
return new self(sprintf("Field '%s' in class '%s' is not a valid field for GridFS documents. You should move it to an embedded metadata document.", $fieldName, $className)); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
public static function discriminatorNotAllowedForGridFS($className) |
|
|
|
|
|
|
406
|
|
|
{ |
|
407
|
|
|
return new self(sprintf("Class '%s' cannot be discriminated because it is marked as a GridFS file")); |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.