GraphAware\Neo4j\OGM\Metadata\QueryResultMapper::addField PHP Method

addField() public method

public addField ( ResultField $field )
$field ResultField
    public function addField(ResultField $field)
    {
        $this->fields[] = $field;
    }

Usage Example

 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;
 }