/**
* @param string $className
*
* @return NodeEntityMetadata|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));
}