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
|
|
|
* @author Jonathan H. Wage <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class MappingException extends BaseMappingException |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @param string $name |
34
|
|
|
* @return MappingException |
35
|
|
|
*/ |
36
|
|
|
public static function typeExists($name) |
37
|
|
|
{ |
38
|
|
|
return new self('Type ' . $name . ' already exists.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $name |
43
|
|
|
* @return MappingException |
44
|
|
|
*/ |
45
|
|
|
public static function typeNotFound($name) |
46
|
|
|
{ |
47
|
|
|
return new self('Type to be overwritten ' . $name . ' does not exist.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $className |
52
|
|
|
* @param string $fieldName |
53
|
|
|
* @return MappingException |
54
|
|
|
*/ |
55
|
3 |
|
public static function mappingNotFound($className, $fieldName) |
56
|
|
|
{ |
57
|
3 |
|
return new self("No mapping found for field '$fieldName' in class '$className'."); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $className |
62
|
|
|
* @param string $fieldName |
63
|
|
|
* @return MappingException |
64
|
|
|
*/ |
65
|
1 |
|
public static function mappingNotFoundInClassNorDescendants($className, $fieldName) |
66
|
|
|
{ |
67
|
1 |
|
return new self("No mapping found for field '$fieldName' in class '$className' nor its descendants."); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $fieldName |
72
|
|
|
* @param $className |
73
|
|
|
* @param $className2 |
74
|
|
|
* @return MappingException |
75
|
|
|
*/ |
76
|
1 |
|
public static function referenceFieldConflict($fieldName, $className, $className2) |
77
|
|
|
{ |
78
|
1 |
|
return new self("Reference mapping for field '$fieldName' in class '$className' conflicts with one mapped in class '$className2'."); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $document |
83
|
|
|
* @param string $fieldName |
84
|
|
|
* @return MappingException |
85
|
|
|
*/ |
86
|
|
|
public static function duplicateFieldMapping($document, $fieldName) |
87
|
|
|
{ |
88
|
|
|
return new self('Property "' . $fieldName . '" in "' . $document . '" was already declared, but it must be declared only once'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $document |
93
|
|
|
* @param string $fieldName |
94
|
|
|
* @return MappingException |
95
|
|
|
*/ |
96
|
2 |
|
public static function discriminatorFieldConflict($document, $fieldName) |
97
|
|
|
{ |
98
|
2 |
|
return new self('Discriminator field "' . $fieldName . '" in "' . $document . '" conflicts with a mapped field\'s "name" attribute.'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Throws an exception that indicates that a class used in a discriminator map does not exist. |
103
|
|
|
* An example would be an outdated (maybe renamed) classname. |
104
|
|
|
* |
105
|
|
|
* @param string $className The class that could not be found |
106
|
|
|
* @param string $owningClass The class that declares the discriminator map. |
107
|
|
|
* @return MappingException |
108
|
|
|
*/ |
109
|
|
|
public static function invalidClassInDiscriminatorMap($className, $owningClass) |
110
|
|
|
{ |
111
|
|
|
return new self( |
112
|
|
|
"Document class '$className' used in the discriminator map of class '$owningClass' " . |
113
|
|
|
"does not exist." |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Throws an exception that indicates a discriminator value does not exist in a map |
119
|
|
|
* |
120
|
|
|
* @param string $value The discriminator value that could not be found |
121
|
|
|
* @param string $owningClass The class that declares the discriminator map |
122
|
|
|
* @return MappingException |
123
|
|
|
*/ |
124
|
|
|
public static function invalidDiscriminatorValue($value, $owningClass) |
125
|
|
|
{ |
126
|
|
|
return new self("Discriminator value '$value' used in the declaration of class '$owningClass' does not exist."); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $className |
131
|
|
|
* @return MappingException |
132
|
|
|
*/ |
133
|
|
|
public static function missingFieldName($className) |
134
|
|
|
{ |
135
|
|
|
return new self("The Document class '$className' field mapping misses the 'fieldName' attribute."); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $className |
140
|
|
|
* @return MappingException |
141
|
|
|
*/ |
142
|
2 |
|
public static function classIsNotAValidDocument($className) |
143
|
|
|
{ |
144
|
2 |
|
return new self('Class ' . $className . ' is not a valid document or mapped super class.'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Exception for reflection exceptions - adds the document name, |
149
|
|
|
* because there might be long classnames that will be shortened |
150
|
|
|
* within the stacktrace |
151
|
|
|
* |
152
|
|
|
* @param string $document The document's name |
153
|
|
|
* @param \ReflectionException $previousException |
154
|
|
|
* @return \Doctrine\ODM\MongoDB\Mapping\MappingException |
155
|
|
|
*/ |
156
|
|
|
public static function reflectionFailure($document, \ReflectionException $previousException) |
157
|
|
|
{ |
158
|
|
|
return new self('An error occurred in ' . $document, 0, $previousException); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param string $documentName |
163
|
|
|
* @return MappingException |
164
|
|
|
*/ |
165
|
|
|
public static function identifierRequired($documentName) |
166
|
|
|
{ |
167
|
|
|
return new self("No identifier/primary key specified for Document '$documentName'." |
168
|
|
|
. " Every Document must have an identifier/primary key."); |
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("The identifier $fieldName is missing for a query of " . $className); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param string $className |
183
|
|
|
* @return MappingException |
184
|
|
|
*/ |
185
|
|
|
public static function missingIdGeneratorClass($className) |
186
|
|
|
{ |
187
|
|
|
return new self("The class-option for the custom ID generator is missing in class $className."); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $className |
192
|
|
|
* @return MappingException |
193
|
|
|
*/ |
194
|
|
|
public static function classIsNotAValidGenerator($className) |
195
|
|
|
{ |
196
|
|
|
return new self("The class $className if not a valid ID generator of type AbstractIdGenerator."); |
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("The class $className is missing a setter for the option $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("Cascade on $className::$fieldName is not allowed."); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param string $className |
221
|
|
|
* @param string $fieldName |
222
|
|
|
* @return MappingException |
223
|
|
|
*/ |
224
|
1 |
|
public static function simpleReferenceRequiresTargetDocument($className, $fieldName) |
225
|
|
|
{ |
226
|
1 |
|
return new self("Target document must be specified for simple reference: $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("Simple reference must not target document using Single Collection Inheritance, $targetDocument targeted."); |
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("$strategy collection strategy can be used only in top level document, used in $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("Target document must be specified for owning/inverse sides of reference: $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("$className::$fieldName was declared an identifier and must stay this way."); |
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("ReferenceMany's sort can not be used with addToSet and pushAll strategies, $strategy used in $className::$fieldName"); |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|