GraphAware\Neo4j\OGM\Metadata\Factory\GraphEntityMetadataFactory::create PHP Method

create() public method

public create ( string $className ) : NodeEntityMetadata | RelationshipEntityMetadata
$className string
return GraphAware\Neo4j\OGM\Metadata\NodeEntityMetadata | GraphAware\Neo4j\OGM\Metadata\RelationshipEntityMetadata
    public function create($className)
    {
        $reflectionClass = new \ReflectionClass($className);
        $entityIdMetadata = null;
        $propertiesMetadata = [];
        $relationshipsMetadata = [];
        if (null !== ($annotation = $this->reader->getClassAnnotation($reflectionClass, Node::class))) {
            $annotationMetadata = $this->nodeAnnotationMetadataFactory->create($className);
            foreach ($reflectionClass->getProperties() as $reflectionProperty) {
                $propertyAnnotationMetadata = $this->propertyAnnotationMetadataFactory->create($className, $reflectionProperty->getName());
                if (null !== $propertyAnnotationMetadata) {
                    $propertiesMetadata[] = new EntityPropertyMetadata($reflectionProperty->getName(), $reflectionProperty, $propertyAnnotationMetadata);
                } else {
                    $idA = $this->IdAnnotationMetadataFactory->create($className, $reflectionProperty);
                    if (null !== $idA) {
                        $entityIdMetadata = new EntityIdMetadata($reflectionProperty->getName(), $reflectionProperty, $idA);
                    }
                }
                foreach ($this->reader->getPropertyAnnotations($reflectionProperty) as $annot) {
                    if ($annot instanceof Label) {
                        $propertiesMetadata[] = new LabeledPropertyMetadata($reflectionProperty->getName(), $reflectionProperty, $annot);
                    }
                    if ($annot instanceof Relationship) {
                        $isLazy = null !== $this->reader->getPropertyAnnotation($reflectionProperty, Lazy::class);
                        $orderBy = $this->reader->getPropertyAnnotation($reflectionProperty, OrderBy::class);
                        $relationshipsMetadata[] = new RelationshipMetadata($className, $reflectionProperty, $annot, $isLazy, $orderBy);
                    }
                }
            }
            return new NodeEntityMetadata($className, $reflectionClass, $annotationMetadata, $entityIdMetadata, $propertiesMetadata, $relationshipsMetadata);
        } elseif (null !== ($annotation = $this->reader->getClassAnnotation($reflectionClass, RelationshipEntity::class))) {
            return $this->relationshipEntityMetadataFactory->create($className);
        }
        if (null !== get_parent_class($className)) {
            return $this->create(get_parent_class($className));
        }
        throw new MappingException(sprintf('The class "%s" is not a valid OGM entity', $className));
    }

Usage Example

 public function testValueCanBeSetOnInstantiatedObject()
 {
     $entityMetadata = $this->entityMetadataFactory->create(Person::class);
     /** @var Person $o */
     $o = $entityMetadata->newInstance();
     $entityMetadata->getPropertyMetadata('name')->setValue($o, 'John');
     $this->assertEquals('John', $o->getName());
 }
All Usage Examples Of GraphAware\Neo4j\OGM\Metadata\Factory\GraphEntityMetadataFactory::create
GraphEntityMetadataFactory