Example #1
0
    /**
     * {@inheritDoc}
     */
    public function loadClassMetadata(ClassMetadata $metadata)
    {
        $reflClass = $metadata->getReflectionClass();
        $className = $reflClass->getName();
        $loaded = false;

        foreach ($this->reader->getClassAnnotations($reflClass) as $index) {
            if ($index instanceof Index) {
                $metadata->setIndex($index);
            }

            $loaded = true;
        }

        foreach ($reflClass->getProperties() as $property) {
            if ($property->getDeclaringClass()->getName() == $className) {
                foreach ($this->reader->getPropertyAnnotations($property) as $type) {
                    if ($type instanceof Field) {
                        $violations = $this->validator->validate($type);
                        if ($violations->count()) {
                            throw new \InvalidArgumentException($violations);
                        }
                        $metadata->addField($property->getName(), $type);
                    }
                    if ($type instanceof Facet)
                    {
                        $metadata->addFacet($property->getName(), $type);
                    }

                    if ($type instanceof Embed) {
                        $metadata->addEmbed($property->getName(), $type);
                    }

                    $loaded = true;
                }
            }
        }

        return $loaded;
    }