source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/ORM/Mapping/MappingException.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 13.0 KB
Line 
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 LGPL. For more information, see
17 * <http://www.phpdoctrine.org>.
18 */
19
20namespace Doctrine\ORM\Mapping;
21
22/**
23 * A MappingException indicates that something is wrong with the mapping setup.
24 *
25 * @since 2.0
26 */
27class 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        return new self("No identifier/primary key specified for Entity '$entityName'."
38                . " Every Entity must have an identifier/primary key.");
39    }
40
41    public static function invalidInheritanceType($entityName, $type)
42    {
43        return new self("The inheritance type '$type' specified for '$entityName' does not exist.");
44    }
45
46    public static function generatorNotAllowedWithCompositeId()
47    {
48        return new self("Id generators can't be used with a composite id.");
49    }
50
51    public static function missingFieldName($entity)
52    {
53        return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
54    }
55
56    public static function missingTargetEntity($fieldName)
57    {
58        return new self("The association mapping '$fieldName' misses the 'targetEntity' attribute.");
59    }
60
61    public static function missingSourceEntity($fieldName)
62    {
63        return new self("The association mapping '$fieldName' misses the 'sourceEntity' attribute.");
64    }
65
66    public static function mappingFileNotFound($entityName, $fileName)
67    {
68        return new self("No mapping file found named '$fileName' for class '$entityName'.");
69    }
70
71    public static function invalidMappingFile($entityName, $fileName)
72    {
73        return new self("Invalid mapping file '$fileName' for class '$entityName'.");
74    }
75
76    public static function mappingNotFound($className, $fieldName)
77    {
78        return new self("No mapping found for field '$fieldName' on class '$className'.");
79    }
80
81    public static function queryNotFound($className, $queryName)
82    {
83        return new self("No query found named '$queryName' on class '$className'.");
84    }
85
86    public static function oneToManyRequiresMappedBy($fieldName)
87    {
88        return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
89    }
90
91    public static function joinTableRequired($fieldName)
92    {
93        return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute.");
94    }
95
96    /**
97     * Called if a required option was not found but is required
98     *
99     * @param string $field which field cannot be processed?
100     * @param string $expectedOption which option is required
101     * @param string $hint  Can optionally be used to supply a tip for common mistakes,
102     *                      e.g. "Did you think of the plural s?"
103     * @return MappingException
104     */
105    static function missingRequiredOption($field, $expectedOption, $hint = '')
106    {
107        $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required.";
108
109        if ( ! empty($hint)) {
110            $message .= ' (Hint: ' . $hint . ')';
111        }
112
113        return new self($message);
114    }
115
116    /**
117     * Generic exception for invalid mappings.
118     *
119     * @param string $fieldName
120     */
121    public static function invalidMapping($fieldName)
122    {
123        return new self("The mapping of field '$fieldName' is invalid.");
124    }
125
126    /**
127     * Exception for reflection exceptions - adds the entity name,
128     * because there might be long classnames that will be shortened
129     * within the stacktrace
130     *
131     * @param string $entity The entity's name
132     * @param \ReflectionException $previousException
133     */
134    public static function reflectionFailure($entity, \ReflectionException $previousException)
135    {
136        return new self('An error occurred in ' . $entity, 0, $previousException);
137    }
138
139    public static function joinColumnMustPointToMappedField($className, $joinColumn)
140    {
141        return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
142                . $className . ' since it is referenced by a join column of another class.');
143    }
144
145    public static function classIsNotAValidEntityOrMappedSuperClass($className)
146    {
147        return new self('Class '.$className.' is not a valid entity or mapped super class.');
148    }
149
150    public static function propertyTypeIsRequired($className, $propertyName)
151    {
152        return new self("The attribute 'type' is required for the column description of property ".$className."::\$".$propertyName.".");
153    }
154
155    public static function tableIdGeneratorNotImplemented($className)
156    {
157        return new self("TableIdGenerator is not yet implemented for use with class ".$className);
158    }
159
160    /**
161     *
162     * @param string $entity The entity's name
163     * @param string $fieldName The name of the field that was already declared
164     */
165    public static function duplicateFieldMapping($entity, $fieldName) {
166        return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
167    }
168
169    public static function duplicateAssociationMapping($entity, $fieldName) {
170        return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
171    }
172
173    public static function duplicateQueryMapping($entity, $queryName) {
174        return new self('Query named "'.$queryName.'" in "'.$entity.'" was already declared, but it must be declared only once');
175    }
176
177    public static function singleIdNotAllowedOnCompositePrimaryKey($entity) {
178        return new self('Single id is not allowed on composite primary key in entity '.$entity);
179    }
180
181    public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) {
182        return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
183                        .'is not supported by Doctrine.'
184        );
185    }
186
187    public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
188    {
189        if ( ! empty($path)) {
190            $path = '[' . $path . ']';
191        }
192
193        return new self(
194            'File mapping drivers must have a valid directory path, ' .
195            'however the given path ' . $path . ' seems to be incorrect!'
196        );
197    }
198
199    /**
200     * Throws an exception that indicates that a class used in a discriminator map does not exist.
201     * An example would be an outdated (maybe renamed) classname.
202     *
203     * @param string $className The class that could not be found
204     * @param string $owningClass The class that declares the discriminator map.
205     * @return self
206     */
207    public static function invalidClassInDiscriminatorMap($className, $owningClass) {
208        return new self(
209            "Entity class '$className' used in the discriminator map of class '$owningClass' ".
210            "does not exist."
211        );
212    }
213
214    public static function missingDiscriminatorMap($className)
215    {
216        return new self("Entity class '$className' is using inheritance but no discriminator map was defined.");
217    }
218
219    public static function missingDiscriminatorColumn($className)
220    {
221        return new self("Entity class '$className' is using inheritance but no discriminator column was defined.");
222    }
223
224    public static function invalidDiscriminatorColumnType($className, $type)
225    {
226        return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
227    }
228
229    public static function cannotVersionIdField($className, $fieldName)
230    {
231        return new self("Setting Id field '$fieldName' as versionale in entity class '$className' is not supported.");
232    }
233
234    public static function sqlConversionNotAllowedForIdentifiers($className, $fieldName, $type)
235    {
236        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.");
237    }
238
239    /**
240     * @param  string $className
241     * @param  string $columnName
242     * @return self
243     */
244    public static function duplicateColumnName($className, $columnName)
245    {
246        return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
247    }
248
249    public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
250    {
251        return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
252    }
253
254    /**
255     * @param string $className
256     * @param string $targetEntity
257     * @param string $targetField
258     * @return self
259     */
260    public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
261    {
262        return new self("It is not possible to map entity '".$className."' with a composite primary key ".
263            "as part of the primary key of another entity '".$targetEntity."#".$targetField."'.");
264    }
265
266    public static function noSingleAssociationJoinColumnFound($className, $field)
267    {
268        return new self("'$className#$field' is not an association with a single join column.");
269    }
270
271    public static function noFieldNameFoundForColumn($className, $column)
272    {
273        return new self("Cannot find a field on '$className' that is mapped to column '$column'. Either the ".
274            "field does not exist or an association exists but it has multiple join columns.");
275    }
276
277    public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
278    {
279        return new self("The orphan removal option is not allowed on an association that is ".
280            "part of the identifier in '$className#$field'.");
281    }
282
283    public static function illegalOrphanRemoval($className, $field)
284    {
285        return new self("Orphan removal is only allowed on one-to-one and one-to-many ".
286                "associations, but " . $className."#" .$field . " is not.");
287    }
288
289    public static function illegalInverseIdentifierAssocation($className, $field)
290    {
291        return new self("An inverse association is not allowed to be identifier in '$className#$field'.");
292    }
293
294    public static function illegalToManyIdentifierAssoaction($className, $field)
295    {
296        return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
297    }
298
299    public static function noInheritanceOnMappedSuperClass($className)
300    {
301        return new self("Its not supported to define inheritance information on a mapped superclass '" . $className . "'.");
302    }
303
304    public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
305    {
306        return new self(
307            "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " .
308            "to be properly mapped in the inheritance hierachy. Alternatively you can make '".$className."' an abstract class " .
309            "to avoid this exception from occuring."
310        );
311    }
312
313    public static function lifecycleCallbackMethodNotFound($className, $methodName)
314    {
315        return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback.");
316    }
317
318    public static function invalidFetchMode($className, $annotation)
319    {
320        return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'");
321    }
322
323    public static function compositeKeyAssignedIdGeneratorRequired($className)
324    {
325        return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported.");
326    }
327
328    public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName)
329    {
330        return new self("The target-entity " . $targetEntity . " cannot be found in '" . $sourceEntity."#".$associationName."'.");
331    }
332}
Note: See TracBrowser for help on using the repository browser.