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\ODM\MongoDB\Mapping; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Persistence\Mapping\MappingException as BaseMappingException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class for all exceptions related to the Doctrine MongoDB ODM |
26
|
|
|
* |
27
|
|
|
* @since 1.0 |
28
|
|
|
*/ |
29
|
|
|
class MappingException extends BaseMappingException |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param string $name |
33
|
|
|
* @return MappingException |
34
|
|
|
*/ |
35
|
|
|
public static function typeExists($name) |
36
|
|
|
{ |
37
|
|
|
return new self('Type ' . $name . ' already exists.'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
* @return MappingException |
43
|
|
|
*/ |
44
|
|
|
public static function typeNotFound($name) |
45
|
|
|
{ |
46
|
|
|
return new self('Type to be overwritten ' . $name . ' does not exist.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $className |
51
|
|
|
* @param string $fieldName |
52
|
|
|
* @return MappingException |
53
|
|
|
*/ |
54
|
6 |
|
public static function mappingNotFound($className, $fieldName) |
55
|
|
|
{ |
56
|
6 |
|
return new self("No mapping found for field '$fieldName' in class '$className'."); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $className |
61
|
|
|
* @param string $fieldName |
62
|
|
|
* @return MappingException |
63
|
|
|
*/ |
64
|
2 |
|
public static function mappingNotFoundInClassNorDescendants($className, $fieldName) |
65
|
|
|
{ |
66
|
2 |
|
return new self("No mapping found for field '$fieldName' in class '$className' nor its descendants."); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $fieldName |
71
|
|
|
* @param $className |
72
|
|
|
* @param $className2 |
73
|
|
|
* @return MappingException |
74
|
|
|
*/ |
75
|
2 |
|
public static function referenceFieldConflict($fieldName, $className, $className2) |
76
|
|
|
{ |
77
|
2 |
|
return new self("Reference mapping for field '$fieldName' in class '$className' conflicts with one mapped in class '$className2'."); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $className |
82
|
|
|
* @param string $dbFieldName |
83
|
|
|
* @return MappingException |
84
|
|
|
*/ |
85
|
|
|
public static function mappingNotFoundByDbName($className, $dbFieldName) |
86
|
|
|
{ |
87
|
|
|
return new self("No mapping found for field by DB name '$dbFieldName' in class '$className'."); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $document |
92
|
|
|
* @param string $fieldName |
93
|
|
|
* @return MappingException |
94
|
|
|
*/ |
95
|
|
|
public static function duplicateFieldMapping($document, $fieldName) |
96
|
|
|
{ |
97
|
|
|
return new self('Property "' . $fieldName . '" in "' . $document . '" was already declared, but it must be declared only once'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $document |
102
|
|
|
* @param string $fieldName |
103
|
|
|
* @return MappingException |
104
|
|
|
*/ |
105
|
2 |
|
public static function discriminatorFieldConflict($document, $fieldName) |
106
|
|
|
{ |
107
|
2 |
|
return new self('Discriminator field "' . $fieldName . '" in "' . $document . '" conflicts with a mapped field\'s "name" attribute.'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Throws an exception that indicates that a class used in a discriminator map does not exist. |
112
|
|
|
* An example would be an outdated (maybe renamed) classname. |
113
|
|
|
* |
114
|
|
|
* @param string $className The class that could not be found |
115
|
|
|
* @param string $owningClass The class that declares the discriminator map. |
116
|
|
|
* @return MappingException |
117
|
|
|
*/ |
118
|
|
|
public static function invalidClassInDiscriminatorMap($className, $owningClass) |
119
|
|
|
{ |
120
|
|
|
return new self( |
121
|
|
|
"Document class '$className' used in the discriminator map of class '$owningClass' " . |
122
|
|
|
'does not exist.' |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Throws an exception that indicates a discriminator value does not exist in a map |
128
|
|
|
* |
129
|
|
|
* @param string $value The discriminator value that could not be found |
130
|
|
|
* @param string $owningClass The class that declares the discriminator map |
131
|
|
|
* @return MappingException |
132
|
|
|
*/ |
133
|
|
|
public static function invalidDiscriminatorValue($value, $owningClass) |
134
|
|
|
{ |
135
|
|
|
return new self("Discriminator value '$value' used in the declaration of class '$owningClass' does not exist."); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $className |
140
|
|
|
* @return MappingException |
141
|
|
|
*/ |
142
|
|
|
public static function missingFieldName($className) |
143
|
|
|
{ |
144
|
|
|
return new self("The Document class '$className' field mapping misses the 'fieldName' attribute."); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $className |
149
|
|
|
* @return MappingException |
150
|
|
|
*/ |
151
|
3 |
|
public static function classIsNotAValidDocument($className) |
152
|
|
|
{ |
153
|
3 |
|
return new self('Class ' . $className . ' is not a valid document or mapped super class.'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Exception for reflection exceptions - adds the document name, |
158
|
|
|
* because there might be long classnames that will be shortened |
159
|
|
|
* within the stacktrace |
160
|
|
|
* |
161
|
|
|
* @param string $document The document's name |
162
|
|
|
* @param \ReflectionException $previousException |
163
|
|
|
* @return \Doctrine\ODM\MongoDB\Mapping\MappingException |
164
|
|
|
*/ |
165
|
|
|
public static function reflectionFailure($document, \ReflectionException $previousException) |
166
|
|
|
{ |
167
|
|
|
return new self('An error occurred in ' . $document, 0, $previousException); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $documentName |
172
|
|
|
* @return MappingException |
173
|
|
|
*/ |
174
|
|
|
public static function identifierRequired($documentName) |
175
|
|
|
{ |
176
|
|
|
return new self("No identifier/primary key specified for Document '$documentName'." |
177
|
|
|
. ' Every Document must have an identifier/primary key.'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $className |
182
|
|
|
* @param string $fieldName |
183
|
|
|
* @return MappingException |
184
|
|
|
*/ |
185
|
|
|
public static function missingIdentifierField($className, $fieldName) |
186
|
|
|
{ |
187
|
|
|
return new self("The identifier $fieldName is missing for a query of " . $className); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $className |
192
|
|
|
* @return MappingException |
193
|
|
|
*/ |
194
|
|
|
public static function missingIdGeneratorClass($className) |
195
|
|
|
{ |
196
|
|
|
return new self("The class-option for the custom ID generator is missing in class $className."); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $className |
201
|
|
|
* @return MappingException |
202
|
|
|
*/ |
203
|
|
|
public static function classIsNotAValidGenerator($className) |
204
|
|
|
{ |
205
|
|
|
return new self("The class $className if not a valid ID generator of type AbstractIdGenerator."); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $className |
210
|
|
|
* @param string $optionName |
211
|
|
|
* @return MappingException |
212
|
|
|
*/ |
213
|
|
|
public static function missingGeneratorSetter($className, $optionName) |
214
|
|
|
{ |
215
|
|
|
return new self("The class $className is missing a setter for the option $optionName."); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param string $className |
220
|
|
|
* @param string $fieldName |
221
|
|
|
* @return MappingException |
222
|
|
|
*/ |
223
|
1 |
|
public static function cascadeOnEmbeddedNotAllowed($className, $fieldName) |
224
|
|
|
{ |
225
|
1 |
|
return new self("Cascade on $className::$fieldName is not allowed."); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @param string $className |
230
|
|
|
* @param string $fieldName |
231
|
|
|
* @return MappingException |
232
|
|
|
*/ |
233
|
1 |
|
public static function simpleReferenceRequiresTargetDocument($className, $fieldName) |
234
|
|
|
{ |
235
|
1 |
|
return new self("Target document must be specified for simple reference: $className::$fieldName"); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param string $targetDocument |
240
|
|
|
* @return MappingException |
241
|
|
|
*/ |
242
|
1 |
|
public static function simpleReferenceMustNotTargetDiscriminatedDocument($targetDocument) |
243
|
|
|
{ |
244
|
1 |
|
return new self("Simple reference must not target document using Single Collection Inheritance, $targetDocument targeted."); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param string $strategy |
249
|
|
|
* @param string $className |
250
|
|
|
* @param string $fieldName |
251
|
|
|
* @return MappingException |
252
|
|
|
*/ |
253
|
1 |
|
public static function atomicCollectionStrategyNotAllowed($strategy, $className, $fieldName) |
254
|
|
|
{ |
255
|
1 |
|
return new self("$strategy collection strategy can be used only in top level document, used in $className::$fieldName"); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string $className |
260
|
|
|
* @param string $fieldName |
261
|
|
|
* @return MappingException |
262
|
|
|
*/ |
263
|
4 |
|
public static function owningAndInverseReferencesRequireTargetDocument($className, $fieldName) |
264
|
|
|
{ |
265
|
4 |
|
return new self("Target document must be specified for owning/inverse sides of reference: $className::$fieldName"); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @param string $className |
270
|
|
|
* @param string $fieldName |
271
|
|
|
* @return MappingException |
272
|
|
|
*/ |
273
|
1 |
|
public static function mustNotChangeIdentifierFieldsType($className, $fieldName) |
274
|
|
|
{ |
275
|
1 |
|
return new self("$className::$fieldName was declared an identifier and must stay this way."); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param string $className |
280
|
|
|
* @param string $fieldName |
281
|
|
|
* @param string $strategy |
282
|
|
|
* @return MappingException |
283
|
|
|
*/ |
284
|
1 |
|
public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($className, $fieldName, $strategy) |
285
|
|
|
{ |
286
|
1 |
|
return new self("ReferenceMany's sort can not be used with addToSet and pushAll strategies, $strategy used in $className::$fieldName"); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @param string $className |
291
|
|
|
* @param string $fieldName |
292
|
|
|
* @param string $type |
293
|
|
|
* @param string $strategy |
294
|
|
|
* @return MappingException |
295
|
|
|
*/ |
296
|
|
|
public static function invalidStorageStrategy($className, $fieldName, $type, $strategy) |
297
|
|
|
{ |
298
|
|
|
return new self("Invalid strategy $strategy used in $className::$fieldName with type $type"); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param string $className |
303
|
|
|
* @param string $fieldName |
304
|
|
|
* @param string $collectionClass |
305
|
|
|
* @return MappingException |
306
|
|
|
*/ |
307
|
1 |
|
public static function collectionClassDoesNotImplementCommonInterface($className, $fieldName, $collectionClass) |
308
|
|
|
{ |
309
|
1 |
|
return new self("$collectionClass used as custom collection class for $className::$fieldName has to implement Doctrine\\Common\\Collections\\Collection interface."); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param $subclassName |
314
|
|
|
* @return MappingException |
315
|
|
|
*/ |
316
|
2 |
|
public static function shardKeyInSingleCollInheritanceSubclass($subclassName) |
317
|
|
|
{ |
318
|
2 |
|
return new self("Shard key overriding in subclass is forbidden for single collection inheritance: $subclassName"); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @param $className |
323
|
|
|
* @return MappingException |
324
|
|
|
*/ |
325
|
1 |
|
public static function embeddedDocumentCantHaveShardKey($className) |
326
|
|
|
{ |
327
|
1 |
|
return new self("Embedded document can't have shard key: $className"); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @param string $className |
332
|
|
|
* @return MappingException |
333
|
|
|
*/ |
334
|
1 |
|
public static function noIncrementFieldsAllowedInShardKey($className) |
335
|
|
|
{ |
336
|
1 |
|
return new self("No increment fields allowed in the shard key: $className"); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|