vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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 
       
    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         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 mappingNotFound($className, $fieldName)
       
    72     {
       
    73         return new self("No mapping found for field '$fieldName' on class '$className'.");
       
    74     }
       
    75 
       
    76     public static function queryNotFound($className, $queryName)
       
    77     {
       
    78         return new self("No query found named '$queryName' on class '$className'.");
       
    79     }
       
    80 
       
    81     public static function oneToManyRequiresMappedBy($fieldName)
       
    82     {
       
    83         return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
       
    84     }
       
    85 
       
    86     public static function joinTableRequired($fieldName)
       
    87     {
       
    88         return new self("The mapping of field '$fieldName' requires an the 'joinTable' attribute.");
       
    89     }
       
    90 
       
    91     /**
       
    92      * Called if a required option was not found but is required
       
    93      *
       
    94      * @param string $field which field cannot be processed?
       
    95      * @param string $expectedOption which option is required
       
    96      * @param string $hint  Can optionally be used to supply a tip for common mistakes,
       
    97      *                      e.g. "Did you think of the plural s?"
       
    98      * @return MappingException
       
    99      */
       
   100     static function missingRequiredOption($field, $expectedOption, $hint = '')
       
   101     {
       
   102         $message = "The mapping of field '{$field}' is invalid: The option '{$expectedOption}' is required.";
       
   103 
       
   104         if ( ! empty($hint)) {
       
   105             $message .= ' (Hint: ' . $hint . ')';
       
   106         }
       
   107 
       
   108         return new self($message);
       
   109     }
       
   110 
       
   111     /**
       
   112      * Generic exception for invalid mappings.
       
   113      *
       
   114      * @param string $fieldName
       
   115      */
       
   116     public static function invalidMapping($fieldName)
       
   117     {
       
   118         return new self("The mapping of field '$fieldName' is invalid.");
       
   119     }
       
   120 
       
   121     /**
       
   122      * Exception for reflection exceptions - adds the entity name,
       
   123      * because there might be long classnames that will be shortened
       
   124      * within the stacktrace
       
   125      *
       
   126      * @param string $entity The entity's name
       
   127      * @param \ReflectionException $previousException
       
   128      */
       
   129     public static function reflectionFailure($entity, \ReflectionException $previousException)
       
   130     {
       
   131         return new self('An error occurred in ' . $entity, 0, $previousException);
       
   132     }
       
   133 
       
   134     public static function joinColumnMustPointToMappedField($className, $joinColumn)
       
   135     {
       
   136         return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
       
   137                 . $className . ' since it is referenced by a join column of another class.');
       
   138     }
       
   139 
       
   140     public static function classIsNotAValidEntityOrMappedSuperClass($className)
       
   141     {
       
   142         return new self('Class '.$className.' is not a valid entity or mapped super class.');
       
   143     }
       
   144 
       
   145     public static function propertyTypeIsRequired($className, $propertyName)
       
   146     {
       
   147         return new self("The attribute 'type' is required for the column description of property ".$className."::\$".$propertyName.".");
       
   148     }
       
   149 
       
   150     public static function tableIdGeneratorNotImplemented($className)
       
   151     {
       
   152         return new self("TableIdGenerator is not yet implemented for use with class ".$className);
       
   153     }
       
   154 
       
   155     /**
       
   156      *
       
   157      * @param string $entity The entity's name
       
   158      * @param string $fieldName The name of the field that was already declared
       
   159      */
       
   160     public static function duplicateFieldMapping($entity, $fieldName) {
       
   161         return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
       
   162     }
       
   163 
       
   164     public static function duplicateAssociationMapping($entity, $fieldName) {
       
   165         return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
       
   166     }
       
   167 
       
   168     public static function duplicateQueryMapping($entity, $queryName) {
       
   169         return new self('Query named "'.$queryName.'" in "'.$entity.'" was already declared, but it must be declared only once');
       
   170     }
       
   171 
       
   172     public static function singleIdNotAllowedOnCompositePrimaryKey($entity) {
       
   173         return new self('Single id is not allowed on composite primary key in entity '.$entity);
       
   174     }
       
   175 
       
   176     public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) {
       
   177         return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
       
   178                         .'is not supported by Doctrine.'
       
   179         );
       
   180     }
       
   181 
       
   182     public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null)
       
   183     {
       
   184         if ( ! empty($path)) {
       
   185             $path = '[' . $path . ']';
       
   186         }
       
   187         
       
   188         return new self(
       
   189             'File mapping drivers must have a valid directory path, ' .
       
   190             'however the given path ' . $path . ' seems to be incorrect!'
       
   191         );
       
   192     }
       
   193 
       
   194     /**
       
   195      * Throws an exception that indicates that a class used in a discriminator map does not exist.
       
   196      * An example would be an outdated (maybe renamed) classname.
       
   197      *
       
   198      * @param string $className The class that could not be found
       
   199      * @param string $owningClass The class that declares the discriminator map.
       
   200      * @return self
       
   201      */
       
   202     public static function invalidClassInDiscriminatorMap($className, $owningClass) {
       
   203         return new self(
       
   204             "Entity class '$className' used in the discriminator map of class '$owningClass' ".
       
   205             "does not exist."
       
   206         );
       
   207     }
       
   208 
       
   209     public static function missingDiscriminatorMap($className)
       
   210     {
       
   211         return new self("Entity class '$className' is using inheritance but no discriminator map was defined.");
       
   212     }
       
   213 
       
   214     public static function missingDiscriminatorColumn($className)
       
   215     {
       
   216         return new self("Entity class '$className' is using inheritance but no discriminator column was defined.");
       
   217     }
       
   218 
       
   219     public static function invalidDiscriminatorColumnType($className, $type)
       
   220     {
       
   221         return new self("Discriminator column type on entity class '$className' is not allowed to be '$type'. 'string' or 'integer' type variables are suggested!");
       
   222     }
       
   223 
       
   224     public static function cannotVersionIdField($className, $fieldName)
       
   225     {
       
   226         return new self("Setting Id field '$fieldName' as versionale in entity class '$className' is not supported.");
       
   227     }
       
   228 
       
   229     /**
       
   230      * @param  string $className
       
   231      * @param  string $columnName
       
   232      * @return self
       
   233      */
       
   234     public static function duplicateColumnName($className, $columnName)
       
   235     {
       
   236         return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
       
   237     }
       
   238 
       
   239     public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
       
   240     {
       
   241         return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
       
   242     }
       
   243 
       
   244     /**
       
   245      * @param string $className
       
   246      * @param string $targetEntity
       
   247      * @param string $targetField
       
   248      * @return self
       
   249      */
       
   250     public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField)
       
   251     {
       
   252         return new self("It is not possible to map entity '".$className."' with a composite primary key ".
       
   253             "as part of the primary key of another entity '".$targetEntity."#".$targetField."'.");
       
   254     }
       
   255 
       
   256     public static function noSingleAssociationJoinColumnFound($className, $field)
       
   257     {
       
   258         return new self("'$className#$field' is not an association with a single join column.");
       
   259     }
       
   260 
       
   261     public static function noFieldNameFoundForColumn($className, $column)
       
   262     {
       
   263         return new self("Cannot find a field on '$className' that is mapped to column '$column'. Either the ".
       
   264             "field does not exist or an association exists but it has multiple join columns.");
       
   265     }
       
   266 
       
   267     public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field)
       
   268     {
       
   269         return new self("The orphan removal option is not allowed on an association that is ".
       
   270             "part of the identifier in '$className#$field'.");
       
   271     }
       
   272 
       
   273     public static function illegalInverseIdentifierAssocation($className, $field)
       
   274     {
       
   275         return new self("An inverse association is not allowed to be identifier in '$className#$field'.");
       
   276     }
       
   277 
       
   278     public static function illegalToManyIdentifierAssoaction($className, $field)
       
   279     {
       
   280         return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
       
   281     }
       
   282     
       
   283     public static function noInheritanceOnMappedSuperClass($className)
       
   284     {
       
   285         return new self("Its not supported to define inheritance information on a mapped superclass '" . $className . "'.");
       
   286     }
       
   287     
       
   288     public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName)
       
   289     {
       
   290         return new self(
       
   291             "Entity '" . $className . "' has to be part of the descriminator map of '" . $rootClassName . "' " .
       
   292             "to be properly mapped in the inheritance hierachy. Alternatively you can make '".$className."' an abstract class " .
       
   293             "to avoid this exception from occuring."
       
   294         );
       
   295     }
       
   296 }