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

create() public method

public create ( $class )
    public function create($class)
    {
        $reflectionClass = new \ReflectionClass($class);
        $annotation = $this->reader->getClassAnnotation($reflectionClass, RelationshipEntity::class);
        $entityIdMetadata = null;
        $startNodeMetadata = null;
        $endNodeMetadata = null;
        $propertiesMetadata = [];
        $startNodeKey = null;
        $endNodeKey = null;
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if (null === $entityIdMetadata && null !== ($idAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, GraphId::class))) {
                $entityIdMetadata = new EntityIdMetadata($reflectionProperty->getName(), $reflectionProperty, new IdAnnotationMetadata());
                continue;
            }
            if (null === $startNodeMetadata && null !== ($startAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, StartNode::class))) {
                $startNodeClass = ClassUtils::getFullClassName($startAnnotation->targetEntity, $class);
                $startNodeMetadata = $startNodeClass;
                $startNodeKey = $reflectionProperty->getName();
                continue;
            }
            if (null === $endNodeMetadata && null !== ($endAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, EndNode::class))) {
                $endNodeClass = ClassUtils::getFullClassName($endAnnotation->targetEntity, $class);
                $endNodeMetadata = $endNodeClass;
                $endNodeKey = $reflectionProperty->getName();
                continue;
            }
            if (null !== ($propertyAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Property::class))) {
                $propertiesMetadata[] = new EntityPropertyMetadata($reflectionProperty->getName(), $reflectionProperty, $this->propertyAnnotationMetadataFactory->create($class, $reflectionProperty->getName()));
            }
        }
        return new RelationshipEntityMetadata($class, $reflectionClass, $annotation, $entityIdMetadata, $startNodeMetadata, $startNodeKey, $endNodeMetadata, $endNodeKey, $propertiesMetadata);
    }

Usage Example

 /**
  * @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));
 }
RelationshipEntityMetadataFactory