Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver::loadMetadataForClass PHP Method

loadMetadataForClass() public method

public loadMetadataForClass ( $className, Doctrine\Common\Persistence\Mapping\ClassMetadata $class )
$class Doctrine\Common\Persistence\Mapping\ClassMetadata
    public function loadMetadataForClass($className, ClassMetadata $class)
    {
        $reflClass = $class->getReflectionClass();
        $isValidDocument = false;
        $classAnnotations = $this->reader->getClassAnnotations($reflClass);
        foreach ($classAnnotations as $classAnnotation) {
            if ($classAnnotation instanceof ODM\Document) {
                if ($classAnnotation->indexed) {
                    $class->indexed = true;
                }
                $class->setCustomRepositoryClass($classAnnotation->repositoryClass);
                $isValidDocument = true;
            } elseif ($classAnnotation instanceof ODM\EmbeddedDocument) {
                $class->isEmbeddedDocument = true;
                $isValidDocument = true;
            } else {
                if ($classAnnotation instanceof ODM\MappedSuperclass) {
                    $class->isMappedSuperclass = true;
                    $isValidDocument = true;
                } else {
                    if ($classAnnotation instanceof ODM\Index) {
                        $class->indexed = true;
                    } else {
                        if ($classAnnotation instanceof ODM\InheritanceRoot) {
                            $class->markInheritanceRoot();
                        }
                    }
                }
            }
        }
        if (!$isValidDocument) {
            throw MappingException::classIsNotAValidDocument($className);
        }
        foreach ($reflClass->getProperties() as $property) {
            if ($class->isInheritedAssociation($property->name) || $class->isInheritedField($property->name)) {
                continue;
            }
            $mapping = array();
            $mapping['fieldName'] = $property->name;
            if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\CouchDB\\Mapping\\Annotations\\Index')) {
                $mapping['indexed'] = true;
            }
            foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
                if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Field) {
                    if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Version) {
                        $mapping['isVersionField'] = true;
                    }
                    $mapping = array_merge($mapping, (array) $fieldAnnot);
                    unset($mapping['value']);
                    $class->mapField($mapping);
                } else {
                    if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
                        $mapping = array_merge($mapping, (array) $fieldAnnot);
                        $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                        unset($mapping['value']);
                        $class->mapManyToOne($mapping);
                    } else {
                        if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
                            $mapping = array_merge($mapping, (array) $fieldAnnot);
                            $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                            unset($mapping['value']);
                            $class->mapManyToMany($mapping);
                        } else {
                            if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
                                $class->mapAttachments($mapping['fieldName']);
                            } else {
                                if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedOne || $fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedMany) {
                                    $mapping = array_merge($mapping, (array) $fieldAnnot);
                                    unset($mapping['value']);
                                    $class->mapEmbedded($mapping);
                                }
                            }
                        }
                    }
                }
            }
        }
    }