/**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $classAnnotations = $this->_reader->getClassAnnotations($class);
     // Compatibility with Doctrine Common 3.x
     if ($classAnnotations && is_int(key($classAnnotations))) {
         foreach ($classAnnotations as $annot) {
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnot->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->readOnly) {
             $metadata->markReadOnly();
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $mappedSuperclassAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate Table annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $primaryTable['indexes'][$indexAnnot->name] = array('columns' => $indexAnnot->columns);
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
                 $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array('columns' => $uniqueConstraint->columns);
             }
         }
         if ($tableAnnot->options !== null) {
             $primaryTable['options'] = $tableAnnot->options;
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnot->value)) {
             throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
         }
         foreach ($namedQueriesAnnot->value as $namedQuery) {
             if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
                 throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($discrMapAnnot->value);
             }
         }
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
     }
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for JoinColummn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'columnDefinition' => $joinColumnAnnot->columnDefinition);
         } else {
             if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
                 }
             }
         }
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['precision'] = $columnAnnot->precision;
             $mapping['scale'] = $columnAnnot->scale;
             $mapping['nullable'] = $columnAnnot->nullable;
             $mapping['unique'] = $columnAnnot->unique;
             if ($columnAnnot->options) {
                 $mapping['options'] = $columnAnnot->options;
             }
             if (isset($columnAnnot->name)) {
                 $mapping['columnName'] = $columnAnnot->name;
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                     $mapping['id'] = true;
                 }
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['indexBy'] = $oneToManyAnnot->indexBy;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
                     if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                         $mapping['orderBy'] = $orderByAnnot->value;
                     }
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                             $mapping['id'] = true;
                         }
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['inversedBy'] = $manyToOneAnnot->inversedBy;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                                     $joinTable['joinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['indexBy'] = $manyToManyAnnot->indexBy;
                             $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
                             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
                             if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                                 $mapping['orderBy'] = $orderByAnnot->value;
                             }
                             $metadata->mapManyToMany($mapping);
                         }
                     }
                 }
             }
         }
     }
     // Evaluate @HasLifecycleCallbacks annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\HasLifecycleCallbacks'])) {
         foreach ($class->getMethods() as $method) {
             // filter for the declaring class only, callbacks from parents will already be registered.
             if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
                 $annotations = $this->_reader->getMethodAnnotations($method);
                 // Compatibility with Doctrine Common 3.x
                 if ($annotations && is_int(key($annotations))) {
                     foreach ($annotations as $annot) {
                         $annotations[get_class($annot)] = $annot;
                     }
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PrePersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostPersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostLoad'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreFlush'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preFlush);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $element = $this->getElement($className);
     if ($element['type'] == 'entity') {
         $metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
     } else {
         if ($element['type'] == 'mappedSuperclass') {
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate root level properties
     $table = array();
     if (isset($element['table'])) {
         $table['name'] = $element['table'];
     }
     $metadata->setPrimaryTable($table);
     /* not implemented specially anyway. use table = schema.table
        if (isset($element['schema'])) {
            $metadata->table['schema'] = $element['schema'];
        }*/
     if (isset($element['inheritanceType'])) {
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate discriminatorColumn
             if (isset($element['discriminatorColumn'])) {
                 $discrColumn = $element['discriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumn['name'], 'type' => $discrColumn['type'], 'length' => $discrColumn['length']));
             } else {
                 throw MappingException::missingDiscriminatorColumn($className);
             }
             // Evaluate discriminatorMap
             if (isset($element['discriminatorMap'])) {
                 $metadata->setDiscriminatorMap($element['discriminatorMap']);
             } else {
                 throw MappingException::missingDiscriminatorMap($className);
             }
         }
     }
     // Evaluate changeTrackingPolicy
     if (isset($element['changeTrackingPolicy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy'])));
     }
     // Evaluate indexes
     if (isset($element['indexes'])) {
         foreach ($element['indexes'] as $name => $index) {
             if (!isset($index['name'])) {
                 $index['name'] = $name;
             }
             if (is_string($index['columns'])) {
                 $columns = explode(',', $index['columns']);
             } else {
                 $columns = $index['columns'];
             }
             $metadata->table['indexes'][$index['name']] = array('columns' => $columns);
         }
     }
     // Evaluate uniqueConstraints
     if (isset($element['uniqueConstraints'])) {
         foreach ($element['uniqueConstraints'] as $name => $unique) {
             if (!isset($unique['name'])) {
                 $unique['name'] = $name;
             }
             if (is_string($unique['columns'])) {
                 $columns = explode(',', $unique['columns']);
             } else {
                 $columns = $unique['columns'];
             }
             $metadata->table['uniqueConstraints'][$unique['name']] = array('columns' => $columns);
         }
     }
     if (isset($element['id'])) {
         // Evaluate identifier settings
         foreach ($element['id'] as $name => $idElement) {
             if (!isset($idElement['type'])) {
                 throw MappingException::propertyTypeIsRequired($className, $name);
             }
             $mapping = array('id' => true, 'fieldName' => $name, 'type' => $idElement['type']);
             if (isset($idElement['column'])) {
                 $mapping['columnName'] = $idElement['column'];
             }
             if (isset($idElement['length'])) {
                 $mapping['length'] = $idElement['length'];
             }
             $metadata->mapField($mapping);
             if (isset($idElement['generator'])) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($idElement['generator']['strategy'])));
             }
             // Check for SequenceGenerator/TableGenerator definition
             if (isset($idElement['sequenceGenerator'])) {
                 $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']);
             } else {
                 if (isset($idElement['tableGenerator'])) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         }
     }
     // Evaluate fields
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $name => $fieldMapping) {
             if (!isset($fieldMapping['type'])) {
                 throw MappingException::propertyTypeIsRequired($className, $name);
             }
             $e = explode('(', $fieldMapping['type']);
             $fieldMapping['type'] = $e[0];
             if (isset($e[1])) {
                 $fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1);
             }
             $mapping = array('fieldName' => $name, 'type' => $fieldMapping['type']);
             if (isset($fieldMapping['id'])) {
                 $mapping['id'] = true;
                 if (isset($fieldMapping['generator']['strategy'])) {
                     $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($fieldMapping['generator']['strategy'])));
                 }
             }
             if (isset($fieldMapping['column'])) {
                 $mapping['columnName'] = $fieldMapping['column'];
             }
             if (isset($fieldMapping['length'])) {
                 $mapping['length'] = $fieldMapping['length'];
             }
             if (isset($fieldMapping['precision'])) {
                 $mapping['precision'] = $fieldMapping['precision'];
             }
             if (isset($fieldMapping['scale'])) {
                 $mapping['scale'] = $fieldMapping['scale'];
             }
             if (isset($fieldMapping['unique'])) {
                 $mapping['unique'] = (bool) $fieldMapping['unique'];
             }
             if (isset($fieldMapping['options'])) {
                 $mapping['options'] = $fieldMapping['options'];
             }
             if (isset($fieldMapping['nullable'])) {
                 $mapping['nullable'] = $fieldMapping['nullable'];
             }
             if (isset($fieldMapping['version']) && $fieldMapping['version']) {
                 $metadata->setVersionMapping($mapping);
             }
             if (isset($fieldMapping['columnDefinition'])) {
                 $mapping['columnDefinition'] = $fieldMapping['columnDefinition'];
             }
             $metadata->mapField($mapping);
         }
     }
     // Evaluate oneToOne relationships
     if (isset($element['oneToOne'])) {
         foreach ($element['oneToOne'] as $name => $oneToOneElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $oneToOneElement['targetEntity']);
             if (isset($oneToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToOneElement['fetch']);
             }
             if (isset($oneToOneElement['mappedBy'])) {
                 $mapping['mappedBy'] = $oneToOneElement['mappedBy'];
             } else {
                 if (isset($oneToOneElement['inversedBy'])) {
                     $mapping['inversedBy'] = $oneToOneElement['inversedBy'];
                 }
                 $joinColumns = array();
                 if (isset($oneToOneElement['joinColumn'])) {
                     $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement['joinColumn']);
                 } else {
                     if (isset($oneToOneElement['joinColumns'])) {
                         foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) {
                             if (!isset($joinColumnElement['name'])) {
                                 $joinColumnElement['name'] = $name;
                             }
                             $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement['cascade'])) {
                 $mapping['cascade'] = $oneToOneElement['cascade'];
             }
             $metadata->mapOneToOne($mapping);
         }
     }
     // Evaluate oneToMany relationships
     if (isset($element['oneToMany'])) {
         foreach ($element['oneToMany'] as $name => $oneToManyElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy']);
             if (isset($oneToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToManyElement['fetch']);
             }
             if (isset($oneToManyElement['cascade'])) {
                 $mapping['cascade'] = $oneToManyElement['cascade'];
             }
             if (isset($oneToManyElement['orderBy'])) {
                 $mapping['orderBy'] = $oneToManyElement['orderBy'];
             }
             $metadata->mapOneToMany($mapping);
         }
     }
     // Evaluate manyToOne relationships
     if (isset($element['manyToOne'])) {
         foreach ($element['manyToOne'] as $name => $manyToOneElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity']);
             if (isset($manyToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToOneElement['fetch']);
             }
             if (isset($manyToOneElement['inversedBy'])) {
                 $mapping['inversedBy'] = $manyToOneElement['inversedBy'];
             }
             $joinColumns = array();
             if (isset($manyToOneElement['joinColumn'])) {
                 $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']);
             } else {
                 if (isset($manyToOneElement['joinColumns'])) {
                     foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $name;
                         }
                         $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                 }
             }
             $mapping['joinColumns'] = $joinColumns;
             if (isset($manyToOneElement['cascade'])) {
                 $mapping['cascade'] = $manyToOneElement['cascade'];
             }
             $metadata->mapManyToOne($mapping);
         }
     }
     // Evaluate manyToMany relationships
     if (isset($element['manyToMany'])) {
         foreach ($element['manyToMany'] as $name => $manyToManyElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $manyToManyElement['targetEntity']);
             if (isset($manyToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToManyElement['fetch']);
             }
             if (isset($manyToManyElement['mappedBy'])) {
                 $mapping['mappedBy'] = $manyToManyElement['mappedBy'];
             } else {
                 if (isset($manyToManyElement['joinTable'])) {
                     if (isset($manyToManyElement['inversedBy'])) {
                         $mapping['inversedBy'] = $manyToManyElement['inversedBy'];
                     }
                     $joinTableElement = $manyToManyElement['joinTable'];
                     $joinTable = array('name' => $joinTableElement['name']);
                     if (isset($joinTableElement['schema'])) {
                         $joinTable['schema'] = $joinTableElement['schema'];
                     }
                     foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $name;
                         }
                         $joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                     foreach ($joinTableElement['inverseJoinColumns'] as $name => $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $name;
                         }
                         $joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                     $mapping['joinTable'] = $joinTable;
                 }
             }
             if (isset($manyToManyElement['cascade'])) {
                 $mapping['cascade'] = $manyToManyElement['cascade'];
             }
             if (isset($manyToManyElement['orderBy'])) {
                 $mapping['orderBy'] = $manyToManyElement['orderBy'];
             }
             $metadata->mapManyToMany($mapping);
         }
     }
     // Evaluate lifeCycleCallbacks
     if (isset($element['lifecycleCallbacks'])) {
         foreach ($element['lifecycleCallbacks'] as $type => $methods) {
             foreach ($methods as $method) {
                 $metadata->addLifecycleCallback($method, constant('Doctrine\\ORM\\Events::' . $type));
             }
         }
     }
 }
 /**
  * Evaluate the property annotations and amend the metadata accordingly.
  *
  * @param ClassMetadataInfo $metadata
  * @return void
  * @throws MappingException
  */
 protected function evaluatePropertyAnnotations(ClassMetadataInfo $metadata)
 {
     $className = $metadata->name;
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($className);
     foreach ($class->getProperties() as $property) {
         if (!$classSchema->hasProperty($property->getName()) || $classSchema->isPropertyTransient($property->getName()) || $metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->getName()) || $metadata->isInheritedAssociation($property->getName())) {
             continue;
         }
         $propertyMetaData = $classSchema->getProperty($property->getName());
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         $mapping['columnName'] = strtolower($property->getName());
         $mapping['targetEntity'] = $propertyMetaData['type'];
         $joinColumns = $this->evaluateJoinColumnAnnotations($property);
         // Field can only be annotated with one of:
         // @OneToOne, @OneToMany, @ManyToOne, @ManyToMany, @Column (optional)
         if ($oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
             if ($oneToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToOneAnnotation->targetEntity;
             }
             if ($oneToOneAnnotation->inversedBy !== null || $oneToOneAnnotation->mappedBy === null) {
                 $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             }
             $mapping['mappedBy'] = $oneToOneAnnotation->mappedBy;
             $mapping['inversedBy'] = $oneToOneAnnotation->inversedBy;
             if ($oneToOneAnnotation->cascade) {
                 $mapping['cascade'] = $oneToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             if ($oneToOneAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToOneAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnotation->fetch);
             $metadata->mapOneToOne($mapping);
         } elseif ($oneToManyAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
             $mapping['mappedBy'] = $oneToManyAnnotation->mappedBy;
             if ($oneToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             if ($oneToManyAnnotation->cascade) {
                 $mapping['cascade'] = $oneToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['indexBy'] = $oneToManyAnnotation->indexBy;
             if ($oneToManyAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToManyAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapOneToMany($mapping);
         } elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
             if ($manyToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
             }
             $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             if ($manyToOneAnnotation->cascade) {
                 $mapping['cascade'] = $manyToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
             $metadata->mapManyToOne($mapping);
         } elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
             if ($manyToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var JoinTable $joinTableAnnotation */
             if ($joinTableAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                 $joinTable = $this->evaluateJoinTableAnnotation($joinTableAnnotation, $property, $className, $mapping);
             } else {
                 $joinColumns = array(array('name' => null, 'referencedColumnName' => null));
                 $joinTable = array('name' => $this->inferJoinTableNameFromClassAndPropertyName($className, $property->getName()), 'joinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property, self::MAPPING_MM_REGULAR), 'inverseJoinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property));
             }
             $mapping['joinTable'] = $joinTable;
             $mapping['mappedBy'] = $manyToManyAnnotation->mappedBy;
             $mapping['inversedBy'] = $manyToManyAnnotation->inversedBy;
             if ($manyToManyAnnotation->cascade) {
                 $mapping['cascade'] = $manyToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['indexBy'] = $manyToManyAnnotation->indexBy;
             $mapping['orphanRemoval'] = $manyToManyAnnotation->orphanRemoval;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapManyToMany($mapping);
         } else {
             $mapping['nullable'] = false;
             /** @var Column $columnAnnotation */
             if ($columnAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
                 $mapping = $this->addColumnToMappingArray($columnAnnotation, $mapping);
             }
             if (!isset($mapping['type'])) {
                 switch ($propertyMetaData['type']) {
                     case 'DateTime':
                         $mapping['type'] = 'datetime';
                         break;
                     case 'string':
                     case 'integer':
                     case 'boolean':
                     case 'float':
                     case 'array':
                         $mapping['type'] = $propertyMetaData['type'];
                         break;
                     default:
                         if (strpos($propertyMetaData['type'], '\\') !== false) {
                             if ($this->reflectionService->isClassAnnotatedWith($propertyMetaData['type'], \TYPO3\Flow\Annotations\ValueObject::class)) {
                                 $mapping['type'] = 'object';
                             } elseif (class_exists($propertyMetaData['type'])) {
                                 throw MappingException::missingRequiredOption($property->getName(), 'OneToOne', sprintf('The property "%s" in class "%s" has a non standard data type and doesn\'t define the type of the relation. You have to use one of these annotations: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany', $property->getName(), $className));
                             }
                         } else {
                             throw MappingException::propertyTypeIsRequired($className, $property->getName());
                         }
                 }
             }
             if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id') !== null) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($generatedValueAnnotation->strategy)));
             }
             if ($this->reflectionService->isPropertyAnnotatedWith($className, $property->getName(), 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnotation->sequenceName, 'allocationSize' => $seqGeneratorAnnotation->allocationSize, 'initialValue' => $seqGeneratorAnnotation->initialValue));
             } elseif ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator') !== null) {
                 throw MappingException::tableIdGeneratorNotImplemented($className);
             } elseif ($customGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\CustomIdGenerator')) {
                 $metadata->setCustomGeneratorDefinition(array('class' => $customGeneratorAnnotation->class));
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $classAnnotations = $this->reader->getClassAnnotations($class);
     if ($classAnnotations) {
         foreach ($classAnnotations as $key => $annot) {
             if (!is_numeric($key)) {
                 continue;
             }
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnot->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->readOnly) {
             $metadata->markReadOnly();
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $mappedSuperclassAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
             $metadata->isMappedSuperclass = true;
         } else {
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Embeddable'])) {
                 $metadata->isEmbeddedClass = true;
             } else {
                 throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
             }
         }
     }
     // Evaluate Table annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $index = array('columns' => $indexAnnot->columns);
                 if (!empty($indexAnnot->flags)) {
                     $index['flags'] = $indexAnnot->flags;
                 }
                 if (!empty($indexAnnot->options)) {
                     $index['options'] = $indexAnnot->options;
                 }
                 if (!empty($indexAnnot->name)) {
                     $primaryTable['indexes'][$indexAnnot->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraintAnnot) {
                 $uniqueConstraint = array('columns' => $uniqueConstraintAnnot->columns);
                 if (!empty($uniqueConstraintAnnot->options)) {
                     $uniqueConstraint['options'] = $uniqueConstraintAnnot->options;
                 }
                 if (!empty($uniqueConstraintAnnot->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraintAnnot->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
         if ($tableAnnot->options) {
             $primaryTable['options'] = $tableAnnot->options;
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate @Cache annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Cache'])) {
         $cacheAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Cache'];
         $cacheMap = array('region' => $cacheAnnot->region, 'usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage));
         $metadata->enableCache($cacheMap);
     }
     // Evaluate NamedNativeQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'])) {
         $namedNativeQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'];
         foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) {
             $metadata->addNamedNativeQuery(array('name' => $namedNativeQuery->name, 'query' => $namedNativeQuery->query, 'resultClass' => $namedNativeQuery->resultClass, 'resultSetMapping' => $namedNativeQuery->resultSetMapping));
         }
     }
     // Evaluate SqlResultSetMappings annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
         $sqlResultSetMappingsAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
         foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) {
             $entities = array();
             $columns = array();
             foreach ($resultSetMapping->entities as $entityResultAnnot) {
                 $entityResult = array('fields' => array(), 'entityClass' => $entityResultAnnot->entityClass, 'discriminatorColumn' => $entityResultAnnot->discriminatorColumn);
                 foreach ($entityResultAnnot->fields as $fieldResultAnnot) {
                     $entityResult['fields'][] = array('name' => $fieldResultAnnot->name, 'column' => $fieldResultAnnot->column);
                 }
                 $entities[] = $entityResult;
             }
             foreach ($resultSetMapping->columns as $columnResultAnnot) {
                 $columns[] = array('name' => $columnResultAnnot->name);
             }
             $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping->name, 'entities' => $entities, 'columns' => $columns));
         }
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnot->value)) {
             throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
         }
         foreach ($namedQueriesAnnot->value as $namedQuery) {
             if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
                 throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type ?: 'string', 'length' => $discrColumnAnnot->length ?: 255, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($discrMapAnnot->value);
             }
         }
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
     }
     // Evaluate annotations on properties/fields
     /* @var $property \ReflectionProperty */
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name) || $metadata->isInheritedEmbeddedClass($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Evaluate @Cache annotation
         if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Cache')) !== null) {
             $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), 'region' => $cacheAnnot->region));
         }
         // Check for JoinColumn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
         } else {
             if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
             }
         }
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping = $this->columnToArray($property->getName(), $columnAnnot);
             if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 } else {
                     if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\CustomIdGenerator')) {
                         $metadata->setCustomGeneratorDefinition(array('class' => $customGeneratorAnnot->class));
                     }
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                     $mapping['id'] = true;
                 }
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['indexBy'] = $oneToManyAnnot->indexBy;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
                     if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                         $mapping['orderBy'] = $orderByAnnot->value;
                     }
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                             $mapping['id'] = true;
                         }
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['inversedBy'] = $manyToOneAnnot->inversedBy;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
                                 }
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['indexBy'] = $manyToManyAnnot->indexBy;
                             $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
                             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
                             if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                                 $mapping['orderBy'] = $orderByAnnot->value;
                             }
                             $metadata->mapManyToMany($mapping);
                         } else {
                             if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Embedded')) {
                                 $mapping['class'] = $embeddedAnnot->class;
                                 $mapping['columnPrefix'] = $embeddedAnnot->columnPrefix;
                                 $metadata->mapEmbedded($mapping);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Evaluate AssociationOverrides annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'])) {
         $associationOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'];
         foreach ($associationOverridesAnnot->value as $associationOverride) {
             $override = array();
             $fieldName = $associationOverride->name;
             // Check for JoinColumn/JoinColumns annotations
             if ($associationOverride->joinColumns) {
                 $joinColumns = array();
                 foreach ($associationOverride->joinColumns as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for JoinTable annotations
             if ($associationOverride->joinTable) {
                 $joinTableAnnot = $associationOverride->joinTable;
                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
                 }
                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                     $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
                 }
                 $override['joinTable'] = $joinTable;
             }
             // Check for inversedBy
             if ($associationOverride->inversedBy) {
                 $override['inversedBy'] = $associationOverride->inversedBy;
             }
             $metadata->setAssociationOverride($fieldName, $override);
         }
     }
     // Evaluate AttributeOverrides annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AttributeOverrides'])) {
         $attributeOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AttributeOverrides'];
         foreach ($attributeOverridesAnnot->value as $attributeOverrideAnnot) {
             $attributeOverride = $this->columnToArray($attributeOverrideAnnot->name, $attributeOverrideAnnot->column);
             $metadata->setAttributeOverride($attributeOverrideAnnot->name, $attributeOverride);
         }
     }
     // Evaluate EntityListeners annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\EntityListeners'])) {
         $entityListenersAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\EntityListeners'];
         foreach ($entityListenersAnnot->value as $item) {
             $listenerClassName = $metadata->fullyQualifiedClassName($item);
             if (!class_exists($listenerClassName)) {
                 throw MappingException::entityListenerClassNotFound($listenerClassName, $className);
             }
             $hasMapping = false;
             $listenerClass = new \ReflectionClass($listenerClassName);
             /* @var $method \ReflectionMethod */
             foreach ($listenerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                 // find method callbacks.
                 $callbacks = $this->getMethodCallbacks($method);
                 $hasMapping = $hasMapping ?: !empty($callbacks);
                 foreach ($callbacks as $value) {
                     $metadata->addEntityListener($value[1], $listenerClassName, $value[0]);
                 }
             }
             // Evaluate the listener using naming convention.
             if (!$hasMapping) {
                 EntityListenerBuilder::bindEntityListener($metadata, $listenerClassName);
             }
         }
     }
     // Evaluate @HasLifecycleCallbacks annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\HasLifecycleCallbacks'])) {
         /* @var $method \ReflectionMethod */
         foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
             foreach ($this->getMethodCallbacks($method) as $value) {
                 $metadata->addLifecycleCallback($value[0], $value[1]);
             }
         }
     }
 }
 /**
  * Evaluate the property annotations and amend the metadata accordingly.
  *
  * @param ORM\ClassMetadataInfo $metadata
  * @return void
  * @throws ORM\MappingException
  */
 protected function evaluatePropertyAnnotations(ORM\ClassMetadataInfo $metadata)
 {
     $className = $metadata->name;
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($className);
     foreach ($class->getProperties() as $property) {
         if (!$classSchema->hasProperty($property->getName()) || $classSchema->isPropertyTransient($property->getName()) || $metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->getName()) || $metadata->isInheritedAssociation($property->getName()) || $metadata->isInheritedEmbeddedClass($property->getName())) {
             continue;
         }
         $propertyMetaData = $classSchema->getProperty($property->getName());
         $mapping = [];
         $mapping['fieldName'] = $property->getName();
         $mapping['columnName'] = strtolower($property->getName());
         $mapping['targetEntity'] = $propertyMetaData['type'];
         $joinColumns = $this->evaluateJoinColumnAnnotations($property);
         // Field can only be annotated with one of:
         // @OneToOne, @OneToMany, @ManyToOne, @ManyToMany, @Column (optional)
         if ($oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToOne::class)) {
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($oneToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToOneAnnotation->targetEntity;
             }
             if ($oneToOneAnnotation->inversedBy !== null || $oneToOneAnnotation->mappedBy === null) {
                 $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             }
             $mapping['mappedBy'] = $oneToOneAnnotation->mappedBy;
             $mapping['inversedBy'] = $oneToOneAnnotation->inversedBy;
             if ($oneToOneAnnotation->cascade) {
                 $mapping['cascade'] = $oneToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             if ($oneToOneAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToOneAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnotation->fetch);
             $metadata->mapOneToOne($mapping);
         } elseif ($oneToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToMany::class)) {
             $mapping['mappedBy'] = $oneToManyAnnotation->mappedBy;
             if ($oneToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             if ($oneToManyAnnotation->cascade) {
                 $mapping['cascade'] = $oneToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['indexBy'] = $oneToManyAnnotation->indexBy;
             if ($oneToManyAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToManyAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OrderBy::class)) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapOneToMany($mapping);
         } elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToOne::class)) {
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($manyToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
             }
             $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             if ($manyToOneAnnotation->cascade) {
                 $mapping['cascade'] = $manyToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
             $metadata->mapManyToOne($mapping);
         } elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToMany::class)) {
             if ($manyToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var ORM\JoinTable $joinTableAnnotation */
             if ($joinTableAnnotation = $this->reader->getPropertyAnnotation($property, ORM\JoinTable::class)) {
                 $joinTable = $this->evaluateJoinTableAnnotation($joinTableAnnotation, $property, $className, $mapping);
             } else {
                 $joinColumns = [['name' => null, 'referencedColumnName' => null]];
                 $joinTable = ['name' => $this->inferJoinTableNameFromClassAndPropertyName($className, $property->getName()), 'joinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property, self::MAPPING_MM_REGULAR), 'inverseJoinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property)];
             }
             $mapping['joinTable'] = $joinTable;
             $mapping['mappedBy'] = $manyToManyAnnotation->mappedBy;
             $mapping['inversedBy'] = $manyToManyAnnotation->inversedBy;
             if ($manyToManyAnnotation->cascade) {
                 $mapping['cascade'] = $manyToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['indexBy'] = $manyToManyAnnotation->indexBy;
             $mapping['orphanRemoval'] = $manyToManyAnnotation->orphanRemoval;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OrderBy::class)) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapManyToMany($mapping);
         } elseif ($embeddedAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Embedded::class)) {
             if ($embeddedAnnotation->class) {
                 $mapping['class'] = $embeddedAnnotation->class;
             } else {
                 // This will not happen currently, because "class" argument is required. It would be nice if that could be changed though.
                 $mapping['class'] = $mapping['targetEntity'];
             }
             $mapping['columnPrefix'] = $embeddedAnnotation->columnPrefix;
             $metadata->mapEmbedded($mapping);
         } else {
             $mapping['nullable'] = false;
             /** @var ORM\Column $columnAnnotation */
             if ($columnAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Column::class)) {
                 $mapping = $this->addColumnToMappingArray($columnAnnotation, $mapping);
             }
             if (!isset($mapping['type'])) {
                 switch ($propertyMetaData['type']) {
                     case 'DateTime':
                         $mapping['type'] = 'datetime';
                         break;
                     case 'string':
                     case 'integer':
                     case 'boolean':
                     case 'float':
                     case 'array':
                         $mapping['type'] = $propertyMetaData['type'];
                         break;
                     default:
                         if (strpos($propertyMetaData['type'], '\\') !== false) {
                             if ($this->reflectionService->isClassAnnotatedWith($propertyMetaData['type'], Flow\ValueObject::class)) {
                                 $valueObjectAnnotation = $this->reflectionService->getClassAnnotation($propertyMetaData['type'], Flow\ValueObject::class);
                                 if ($valueObjectAnnotation->embedded === true) {
                                     $mapping['class'] = $propertyMetaData['type'];
                                     $mapping['columnPrefix'] = $mapping['columnName'];
                                     $metadata->mapEmbedded($mapping);
                                     // Leave switch and continue with next property
                                     continue 2;
                                 }
                                 $mapping['type'] = 'object';
                             } elseif (class_exists($propertyMetaData['type'])) {
                                 throw ORM\MappingException::missingRequiredOption($property->getName(), 'OneToOne', sprintf('The property "%s" in class "%s" has a non standard data type and doesn\'t define the type of the relation. You have to use one of these annotations: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany', $property->getName(), $className));
                             }
                         } else {
                             throw ORM\MappingException::propertyTypeIsRequired($className, $property->getName());
                         }
                 }
             }
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnotation = $this->reader->getPropertyAnnotation($property, ORM\GeneratedValue::class)) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($generatedValueAnnotation->strategy)));
             }
             if ($this->reflectionService->isPropertyAnnotatedWith($className, $property->getName(), ORM\Version::class)) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, ORM\SequenceGenerator::class)) {
                 $metadata->setSequenceGeneratorDefinition(['sequenceName' => $seqGeneratorAnnotation->sequenceName, 'allocationSize' => $seqGeneratorAnnotation->allocationSize, 'initialValue' => $seqGeneratorAnnotation->initialValue]);
             } elseif ($this->reader->getPropertyAnnotation($property, ORM\TableGenerator::class) !== null) {
                 throw ORM\MappingException::tableIdGeneratorNotImplemented($className);
             } elseif ($customGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, ORM\CustomIdGenerator::class)) {
                 $metadata->setCustomGeneratorDefinition(['class' => $customGeneratorAnnotation->class]);
             }
         }
         // Evaluate @Cache annotation
         if (($cacheAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Cache::class)) !== null) {
             $metadata->enableAssociationCache($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnotation->usage), 'region' => $cacheAnnotation->region));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
 {
     $class = $metadata->getReflectionClass();
     $classAnnotations = $this->_reader->getClassAnnotations($class);
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate DoctrineTable annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $primaryTable['indexes'][$indexAnnot->name] = array('columns' => $indexAnnot->columns);
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraint) {
                 $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = array('columns' => $uniqueConstraint->columns);
             }
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('\\Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
     }
     // Evaluate DiscriminatorColumn annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
         $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
         $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length));
     }
     // Evaluate DiscriminatorMap annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
         $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
         $metadata->setDiscriminatorMap($discrMapAnnot->value);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
     }
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for JoinColummn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'onUpdate' => $joinColumnAnnot->onUpdate, 'columnDefinition' => $joinColumnAnnot->columnDefinition);
         } else {
             if ($joinColumnsAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                 }
             }
         }
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['precision'] = $columnAnnot->precision;
             $mapping['scale'] = $columnAnnot->scale;
             $mapping['nullable'] = $columnAnnot->nullable;
             $mapping['unique'] = $columnAnnot->unique;
             if ($columnAnnot->options) {
                 $mapping['options'] = $columnAnnot->options;
             }
             if (isset($columnAnnot->name)) {
                 $mapping['columnName'] = $columnAnnot->name;
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToManyAnnot->fetch);
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $manyToOneAnnot->fetch);
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                                     $joinTable['joinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $manyToManyAnnot->fetch);
                             $metadata->mapManyToMany($mapping);
                         }
                     }
                 }
             }
         }
     }
     // Evaluate HasLifecycleCallbacks annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\HasLifecycleCallbacks'])) {
         foreach ($class->getMethods() as $method) {
             if ($method->isPublic()) {
                 $annotations = $this->_reader->getMethodAnnotations($method);
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PrePersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostPersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostLoad'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
                 }
             }
         }
     }
 }