Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Mapping / MappingException.php
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.phpdoctrine.org>.
18  */
19
20 namespace Doctrine\ORM\Mapping;
21
22 /**
23  * A MappingException indicates that something is wrong with the mapping setup.
24  *
25  * @since 2.0
26  */
27 class MappingException extends \Doctrine\ORM\ORMException
28 {
29     public static function pathRequired()
30     {
31         return new self("Specifying the paths to your entities is required ".
32             "in the AnnotationDriver to retrieve all class names.");
33     }
34
35     public static function identifierRequired($entityName)
36     {
37         if (null !== ($parent = get_parent_class($entityName))) {
38             return new self(sprintf(
39                 'No identifier/primary key specified for Entity "%s" sub class of "%s". Every Entity must have an identifier/primary key.',
40                 $entityName, $parent
41             ));
42         }
43
44         return new self(sprintf(
45             'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.',
46             $entityName
47         ));
48
49     }
50
51     public static function invalidInheritanceType($entityName, $type)
52     {
53         return new self("The inheritance type '$type' specified for '$entityName' does not exist.");
54     }
55
56     public static function generatorNotAllowedWithCompositeId()
57     {
58         return new self("Id generators can't be used with a composite id.");
59     }
60
61     public static function missingFieldName($entity)
62     {
63         return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
64     }
65
66     public static function missingTargetEntity($fieldName)
67     {
68         return new self("The association mapping '$fieldName' misses the 'targetEntity' attribute.");
69     }
70
71     public static function missingSourceEntity($fieldName)
72     {
73         return new self("The association mapping '$fieldName' misses the 'sourceEntity' attribute.");
74     }
75
76     public static function mappingFileNotFound($entityName, $fileName)
77     {
78         return new self("No mapping file found named '$fileName' for class '$entityName'.");
79     }
80
81      /**
82      * Exception for invalid property name override.
83      *
84      * @param string $className The entity's name
85      * @param string $fieldName
86      */
87     public static function invalidOverrideFieldName($className, $fieldName)
88     {
89         return new self("Invalid field override named '$fieldName' for class '$className'.");
90     }
91
92     /**
93      * Exception for invalid property type override.
94      *
95      * @param string $className The entity's name
96      * @param string $fieldName
97      */
98     public static function invalidOverrideFieldType($className, $fieldName)
99     {
100         return new self("The column type of attribute '$fieldName' on class '$className' could not be changed.");
101     }
102
103     public static function mappingNotFound($className, $fieldName)
104     {
105         return new self("No mapping found for field '$fieldName' on class '$className'.");
106     }
107
108     public static function queryNotFound($className, $queryName)
109     {
110         return new self("No query found named '$queryName' on class '$className'.");
111     }
112
113     public static function resultMappingNotFound($className, $resultName)
114     {
115         return new self("No result set mapping found named '$resultName' on class '$className'.");
116     }
117
118     public static function emptyQueryMapping($entity, $queryName)
119     {
120         return new self('Query named "'.$queryName.'" in "'.$entity.'" could not be empty.');
121     }
122
123     public static function nameIsMandatoryForQueryMapping($className)
124     {
125         return new self("Query name on entity class '$className' is not defined.");
126     }
127
128     public static function missingQueryMapping($entity, $queryName)
129     {
130         return new self('Query named "'.$queryName.'" in "'.$entity.' requires a result class or result set mapping.');
131     }
132
133     public static function missingResultSetMappingEntity($entity, $resultName)
134     {
135         return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a entity class name.');
136     }
137
138     public static function missingResultSetMappingFieldName($entity, $resultName)
139     {
140         return new self('Result set mapping named "'.$resultName.'" in "'.$entity.' requires a field name.');
141     }
142
143     public static function nameIsMandatoryForSqlResultSetMapping($className)
144     {
145         return new self("Result set mapping name on entity class '$className' is not defined.");
146     }
147
148     public static function oneToManyRequiresMappedBy($fieldName)
149     {
150         return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
151     }
152
153     public static function joinTableRequired($fieldName)
154     {
155         return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute.");
156     }
157
158     /**
159      * Called if a required option was not found but is required
160      *
161      * @param string $field which field cannot be processed?
162      * @param string $expectedOption which option is required
163      * @param string $hint  Can optionally be used to supply a tip for common mistakes,
164      *                      e.g. "Did you think of the plural s?"
165      * @return MappingException
166      */
167     static function missingRequiredOption($field, $expectedOption, $hint = '')
168     {
169         $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required.";
170
171         if ( ! empty($hint)) {
172             $message .= ' (Hint: ' . $hint . ')';
173         }
174
175         return new self($message);
176     }
177
178     /**
179      * Generic exception for invalid mappings.
180      *
181      * @param string $fieldName
182      */
183     public static function invalidMapping($fieldName)
184     {
185         return new self("The mapping of field '$fieldName' is invalid.");
186     }
187
188     /**
189      * Exception for reflection exceptions - adds the entity name,
190      * because there might be long classnames that will be shortened
191      * within the stacktrace
192      *
193      * @param string $entity The entity's name
194      * @param \ReflectionException $previousException
195      */
196     public static function reflectionFailure($entity, \ReflectionException $previousException)
197     {
198         return new self('An error occurred in ' . $entity, 0, $previousException);
199     }
200
201     public static function joinColumnMustPointToMappedField($className, $joinColumn)
202     {
203         return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
204                 . $className . ' since it is referenced by a join column of another class.');
205     }
206
207     public static function classIsNotAValidEntityOrMappedSuperClass($className)
208     {
209         if (null !== ($parent = get_parent_class($className))) {
210             return new self(sprintf(
211                 'Class "%s" sub class of "%s" is not a valid entity or mapped super class.',
212                 $className, $parent
213             ));
214         }
215
216         return new self(sprintf(
217             'Class "%s" is not a valid entity or mapped super class.',
218             $className
219         ));
220     }
221
222     public static function propertyTypeIsRequired($className, $propertyName)
223     {
224         return new self("The attribute 'type' is required for the column description of property ".$className."::\$".$propertyName.".");
225     }
226
227     public static function tableIdGeneratorNotImplemented($className)
228     {
229         return new self("TableIdGenerator is not yet implemented for use with class ".$className);
230     }
231
232     /**
233      * @param string $entity The entity's name
234      * @param string $fieldName The name of the field that was already declared
235      */
236     public static function duplicateFieldMapping($entity, $fieldName)
237     {
238         return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
239     }
240
241     public static function duplicateAssociationMapping($entity, $fieldName)
242     {
243         return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
244     }
245
246     public static function duplicateQueryMapping($entity, $queryName)
247     {
248         return new self('Query named "'.$queryName.'" in "'.$entity.'" was already declared, but it must be declared only once');
249     }
250
251     public static function duplicateResultSetMapping($entity, $resultName)
252     {
253         return new self('Result set mapping named "'.$resultName.'" in "'.$entity.'" was already declared, but it must be declared only once');
254     }
255
256     public static function singleIdNotAllowedOnCompositePrimaryKey($entity)
257     {
258         return new self('Single id is not allowed on composite primary key in entity '.$entity);
259     }
260
261     public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType)
262     {
263         return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
264                         .'is not supported by Doctrine.'
265         );
266     }
267
268     public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
269     {
270         if ( ! empty($path)) {
271             $path = '[' . $path . ']';
272         }
273
274         return new self(
275             'File mapping drivers must have a valid directory path, ' .
276             'however the given path ' . $path . ' seems to be incorrect!'
277         );
278     }
279
280     /**
281      * Throws an exception that indicates that a class used in a discriminator map does not exist.
282      * An example would be an outdated (maybe renamed) classname.
283      *
284      * @param string $className The class that could not be found
285      * @param string $owningClass The class that declares the discriminator map.
286      * @return self
287      */
288     public static function invalidClassInDiscriminatorMap($className, $owningClass)
289     {
290         return new self(
291             "Entity class '$className' used in the discriminator map of class '$owningClass' ".
292             "does not exist."
293         );
294     }
295
296     public static function duplicateDiscriminatorEntry($className, array $entries, array $map)
297     {
298         return new self(
299             "The entries " . implode(', ',  $entries) . " in discriminator map of class '" . $className . "' is duplicated. " .
300             "If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. " .
301             "The entries of the current map are: @DiscriminatorMap({" . implode(', ', array_map(
302                 function($a, $b) { return "'$a': '$b'"; }, array_keys($map), array_values($map)
303             )) . "})"
304         );
305     }
306
307     public static function missingDiscriminatorMap($className)
308     {
309         return new self("Entity class '$className' is using inheritance but no discriminator map was defined.");
310     }
311
312     public static function missingDiscriminatorColumn($className)
313     {
314         return new self("Entity class '$className' is using inheritance but no discriminator column was defined.");
315     }
316
317     public static function invalidDiscriminatorColumnType($className, $type)
318     {
319         return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
320     }
321
322     public static function nameIsMandatoryForDiscriminatorColumns($className)
323     {
324         return new self("Discriminator column name on entity class '$className' is not defined.");
325     }
326
327     public static function cannotVersionIdField($className, $fieldName)
328     {
329         return new self("Setting Id field '$fieldName' as versionale in entity class '$className' is not supported.");
330     }
331
332     public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
333     {
334         return new self("It is not possible to set id field '$fieldName' to type '$type' in entity class '$className'. The type '$type' requires conversion SQL which is not allowed for identifiers.");
335     }
336
337     /**
338      * @param  string $className
339      * @param  string $columnName
340      * @return self
341      */
342     public static function duplicateColumnName($className, $columnName)
343     {
344         return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
345     }
346
347     public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
348     {
349         return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
350     }
351
352     /**
353      * @param string $className
354      * @param string $targetEntity
355      * @param string $targetField
356      * @return self
357      */
358     public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
359     {
360         return new self("It is not possible to map entity '".$className."' with a composite primary key ".
361             "as part of the primary key of another entity '".$targetEntity."#".$targetField."'.");
362     }
363
364     public static function noSingleAssociationJoinColumnFound($className, $field)
365     {
366         return new self("'$className#$field' is not an association with a single join column.");
367     }
368
369     public static function noFieldNameFoundForColumn($className, $column)
370     {
371         return new self("Cannot find a field on '$className' that is mapped to column '$column'. Either the ".
372             "field does not exist or an association exists but it has multiple join columns.");
373     }
374
375     public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
376     {
377         return new self("The orphan removal option is not allowed on an association that is ".
378             "part of the identifier in '$className#$field'.");
379     }
380
381     public static function illegalOrphanRemoval($className, $field)
382     {
383         return new self("Orphan removal is only allowed on one-to-one and one-to-many ".
384                 "associations, but " . $className."#" .$field . " is not.");
385     }
386
387     public static function illegalInverseIdentifierAssocation($className, $field)
388     {
389         return new self("An inverse association is not allowed to be identifier in '$className#$field'.");
390     }
391
392     public static function illegalToManyIdentifierAssoaction($className, $field)
393     {
394         return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
395     }
396
397     public static function noInheritanceOnMappedSuperClass($className)
398     {
399         return new self("Its not supported to define inheritance information on a mapped superclass '" . $className . "'.");
400     }
401
402     public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
403     {
404         return new self(
405             "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
406             "to be properly mapped in the inheritance hierachy. Alternatively you can make '".$className."' an abstract class " .
407             "to avoid this exception from occuring."
408         );
409     }
410
411     public static function lifecycleCallbackMethodNotFound($className, $methodName)
412     {
413         return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
414     }
415
416     public static function invalidFetchMode($className, $annotation)
417     {
418         return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
419     }
420
421     public static function compositeKeyAssignedIdGeneratorRequired($className)
422     {
423         return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
424     }
425
426     public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
427     {
428         return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
429     }
430
431     public static function invalidCascadeOption(array $cascades, $className, $propertyName)
432     {
433         $cascades = implode(", ", array_map(function ($e) { return "'" . $e . "'"; }, $cascades));
434         return new self(sprintf(
435             "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'",
436             $className,
437             $propertyName,
438             $cascades
439         ));
440     }
441 }