GraphAware\Neo4j\OGM\Mapping\AnnotationDriver::readQueryResult PHP Method

readQueryResult() public method

public readQueryResult ( $class )
    public function readQueryResult($class)
    {
        $reflClass = new \ReflectionClass($class);
        $classAnnotations = $this->reader->getClassAnnotations($reflClass);
        $isQueryResult = false;
        foreach ($classAnnotations as $classAnnotation) {
            if ($classAnnotation instanceof QueryResult) {
                $isQueryResult = true;
            }
        }
        if (!$isQueryResult) {
            throw new \RuntimeException(sprintf('The class "%s" is not a valid QueryResult entity', $class));
        }
        $queryResultMapper = new QueryResultMapper($class);
        foreach ($reflClass->getProperties() as $property) {
            foreach ($this->reader->getPropertyAnnotations($property) as $propertyAnnotation) {
                if ($propertyAnnotation instanceof MappedResult) {
                    $queryResultMapper->addField(new ResultField($property->getName(), $propertyAnnotation->type, $propertyAnnotation->target));
                }
            }
        }
        return $queryResultMapper;
    }

Usage Example

 public function getResultMappingMetadata($class)
 {
     if (!array_key_exists($class, $this->resultMappers)) {
         $this->resultMappers[$class] = $this->annotationDriver->readQueryResult($class);
         foreach ($this->resultMappers[$class]->getFields() as $field) {
             if ($field->isEntity()) {
                 $targetFQDN = ClassUtils::getFullClassName($field->getTarget(), $class);
                 $field->setMetadata($this->getClassMetadataFor($targetFQDN));
             }
         }
     }
     return $this->resultMappers[$class];
 }