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
|
2 |
|
public static function mappingNotFound($className, $fieldName) |
56
|
|
|
{ |
57
|
2 |
|
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 string $document |
72
|
|
|
* @param string $fieldName |
73
|
|
|
* @return MappingException |
74
|
|
|
*/ |
75
|
|
|
public static function duplicateFieldMapping($document, $fieldName) |
76
|
|
|
{ |
77
|
|
|
return new self('Property "' . $fieldName . '" in "' . $document . '" was already declared, but it must be declared only once'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $document |
82
|
|
|
* @param string $fieldName |
83
|
|
|
* @return MappingException |
84
|
|
|
*/ |
85
|
2 |
|
public static function discriminatorFieldConflict($document, $fieldName) |
86
|
|
|
{ |
87
|
2 |
|
return new self('Discriminator field "' . $fieldName . '" in "' . $document . '" conflicts with a mapped field\'s "name" attribute.'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Throws an exception that indicates that a class used in a discriminator map does not exist. |
92
|
|
|
* An example would be an outdated (maybe renamed) classname. |
93
|
|
|
* |
94
|
|
|
* @param string $className The class that could not be found |
95
|
|
|
* @param string $owningClass The class that declares the discriminator map. |
96
|
|
|
* @return MappingException |
97
|
|
|
*/ |
98
|
|
|
public static function invalidClassInDiscriminatorMap($className, $owningClass) |
99
|
|
|
{ |
100
|
|
|
return new self( |
101
|
|
|
"Document class '$className' used in the discriminator map of class '$owningClass' " . |
102
|
|
|
"does not exist." |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Throws an exception that indicates a discriminator value does not exist in a map |
108
|
|
|
* |
109
|
|
|
* @param string $value The discriminator value that could not be found |
110
|
|
|
* @param string $owningClass The class that declares the discriminator map |
111
|
|
|
* @return MappingException |
112
|
|
|
*/ |
113
|
|
|
public static function invalidDiscriminatorValue($value, $owningClass) |
114
|
|
|
{ |
115
|
|
|
return new self("Discriminator value '$value' used in the declaration of class '$owningClass' does not exist."); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $className |
120
|
|
|
* @return MappingException |
121
|
|
|
*/ |
122
|
|
|
public static function missingFieldName($className) |
123
|
|
|
{ |
124
|
|
|
return new self("The Document class '$className' field mapping misses the 'fieldName' attribute."); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $className |
129
|
|
|
* @return MappingException |
130
|
|
|
*/ |
131
|
2 |
|
public static function classIsNotAValidDocument($className) |
132
|
|
|
{ |
133
|
2 |
|
return new self('Class ' . $className . ' is not a valid document or mapped super class.'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Exception for reflection exceptions - adds the document name, |
138
|
|
|
* because there might be long classnames that will be shortened |
139
|
|
|
* within the stacktrace |
140
|
|
|
* |
141
|
|
|
* @param string $document The document's name |
142
|
|
|
* @param \ReflectionException $previousException |
143
|
|
|
* @return \Doctrine\ODM\MongoDB\Mapping\MappingException |
144
|
|
|
*/ |
145
|
|
|
public static function reflectionFailure($document, \ReflectionException $previousException) |
146
|
|
|
{ |
147
|
|
|
return new self('An error occurred in ' . $document, 0, $previousException); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $documentName |
152
|
|
|
* @return MappingException |
153
|
|
|
*/ |
154
|
|
|
public static function identifierRequired($documentName) |
155
|
|
|
{ |
156
|
|
|
return new self("No identifier/primary key specified for Document '$documentName'." |
157
|
|
|
. " Every Document must have an identifier/primary key."); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $className |
162
|
|
|
* @param string $fieldName |
163
|
|
|
* @return MappingException |
164
|
|
|
*/ |
165
|
|
|
public static function missingIdentifierField($className, $fieldName) |
166
|
|
|
{ |
167
|
|
|
return new self("The identifier $fieldName is missing for a query of " . $className); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $className |
172
|
|
|
* @return MappingException |
173
|
|
|
*/ |
174
|
|
|
public static function missingIdGeneratorClass($className) |
175
|
|
|
{ |
176
|
|
|
return new self("The class-option for the custom ID generator is missing in class $className."); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $className |
181
|
|
|
* @return MappingException |
182
|
|
|
*/ |
183
|
|
|
public static function classIsNotAValidGenerator($className) |
184
|
|
|
{ |
185
|
|
|
return new self("The class $className if not a valid ID generator of type AbstractIdGenerator."); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $className |
190
|
|
|
* @param string $optionName |
191
|
|
|
* @return MappingException |
192
|
|
|
*/ |
193
|
|
|
public static function missingGeneratorSetter($className, $optionName) |
194
|
|
|
{ |
195
|
|
|
return new self("The class $className is missing a setter for the option $optionName."); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $className |
200
|
|
|
* @param string $fieldName |
201
|
|
|
* @return MappingException |
202
|
|
|
*/ |
203
|
1 |
|
public static function cascadeOnEmbeddedNotAllowed($className, $fieldName) |
204
|
|
|
{ |
205
|
1 |
|
return new self("Cascade on $className::$fieldName is not allowed."); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $className |
210
|
|
|
* @param string $fieldName |
211
|
|
|
* @return MappingException |
212
|
|
|
*/ |
213
|
1 |
|
public static function simpleReferenceRequiresTargetDocument($className, $fieldName) |
214
|
|
|
{ |
215
|
1 |
|
return new self("Target document must be specified for simple reference: $className::$fieldName"); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param string $targetDocument |
220
|
|
|
* @return MappingException |
221
|
|
|
*/ |
222
|
1 |
|
public static function simpleReferenceMustNotTargetDiscriminatedDocument($targetDocument) |
223
|
|
|
{ |
224
|
1 |
|
return new self("Simple reference must not target document using Single Collection Inheritance, $targetDocument targeted."); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string $strategy |
229
|
|
|
* @param string $className |
230
|
|
|
* @param string $fieldName |
231
|
|
|
* @return MappingException |
232
|
|
|
*/ |
233
|
1 |
|
public static function atomicCollectionStrategyNotAllowed($strategy, $className, $fieldName) |
234
|
|
|
{ |
235
|
1 |
|
return new self("$strategy collection strategy can be used only in top level document, used in $className::$fieldName"); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param string $className |
240
|
|
|
* @param string $fieldName |
241
|
|
|
* @return MappingException |
242
|
|
|
*/ |
243
|
4 |
|
public static function owningAndInverseReferencesRequireTargetDocument($className, $fieldName) |
244
|
|
|
{ |
245
|
4 |
|
return new self("Target document must be specified for owning/inverse sides of reference: $className::$fieldName"); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param string $className |
250
|
|
|
* @param string $fieldName |
251
|
|
|
* @return MappingException |
252
|
|
|
*/ |
253
|
1 |
|
public static function mustNotChangeIdentifierFieldsType($className, $fieldName) |
254
|
|
|
{ |
255
|
1 |
|
return new self("$className::$fieldName was declared an identifier and must stay this way."); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string $className |
260
|
|
|
* @param string $fieldName |
261
|
|
|
* @param string $strategy |
262
|
|
|
* @return MappingException |
263
|
|
|
*/ |
264
|
1 |
|
public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($className, $fieldName, $strategy) |
265
|
|
|
{ |
266
|
1 |
|
return new self("ReferenceMany's sort can not be used with addToSet and pushAll strategies, $strategy used in $className::$fieldName"); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|