/**
  * Validate Identifier
  *
  * @throws MappingException
  * @return void
  */
 public function validateIdentifier()
 {
     // Verify & complete identifier mapping
     if (!$this->identifier && !$this->isMappedSuperclass) {
         throw MappingException::identifierRequired($this->name);
     }
     if ($this->usesIdGenerator() && $this->isIdentifierComposite) {
         throw MappingException::compositeKeyAssignedIdGeneratorRequired($this->name);
     }
 }
Ejemplo n.º 2
0
 /**
  * Validate runtime metadata is correctly defined.
  *
  * @param ClassMetadata $class
  * @param ClassMetadata $parent
  */
 protected function validateRuntimeMetadata($class, $parent)
 {
     // Verify & complete identifier mapping
     if (!$class->identifier && !$class->isMappedSuperclass) {
         throw MappingException::identifierRequired($class->name);
     }
     // verify inheritance
     if (!$class->isMappedSuperclass && !$class->isInheritanceTypeNone()) {
         if (!$parent) {
             if (count($class->discriminatorMap) == 0) {
                 throw MappingException::missingDiscriminatorMap($class->name);
             }
             if (!$class->discriminatorColumn) {
                 throw MappingException::missingDiscriminatorColumn($class->name);
             }
         } else {
             if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
                 // enforce discriminator map for all entities of an inheritance hierachy, otherwise problems will occur.
                 throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
             }
         }
     } else {
         if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
             // second condition is necessary for mapped superclasses in the middle of an inheritance hierachy
             throw MappingException::noInheritanceOnMappedSuperClass($class->name);
         }
     }
     if ($class->usesIdGenerator() && $class->isIdentifierComposite) {
         throw MappingException::compositeKeyAssignedIdGeneratorRequired($class->name);
     }
 }