GraphAware\Neo4j\OGM\Repository\BaseRepository::hydrateNode PHP Méthode

hydrateNode() private méthode

private hydrateNode ( GraphAware\Common\Type\Node $node, $className = null, $andProxy = false )
$node GraphAware\Common\Type\Node
    private function hydrateNode(Node $node, $className = null, $andProxy = false)
    {
        if ($entity = $this->entityManager->getUnitOfWork()->getEntityById($node->identity())) {
            return $entity;
        }
        $cl = $className !== null ? $className : $this->className;
        $cm = $className === null ? $this->classMetadata : $this->entityManager->getClassMetadataFor($cl);
        $pmVersion = !method_exists(Version::class, 'getVersion') ? 1 : (int) Version::getVersion()[0];
        $em = $this->entityManager;
        if ($andProxy) {
            if ($pmVersion >= 2) {
                $initializer = function ($ghostObject, $method, array $parameters, &$initializer, array $properties) use($cm, $node, $em, $pmVersion) {
                    $initializer = null;
                    /*
                    foreach ($cm->getPropertiesMetadata() as $field => $meta) {
                        if ($node->hasValue($field)) {
                    
                            $key = null;
                            if ($meta->getReflectionProperty()->isPrivate()) {
                                $key = '\\0' . $cm->getClassName() . '\\0' . $meta->getPropertyName();
                            } else if($meta->getReflectionProperty()->isProtected()) {
                                $key = '' . "\0" . '*' . "\0" . $meta->getPropertyName();
                            } else if ($meta->getReflectionProperty()->isPublic()) {
                                $key = $meta->getPropertyName();
                            }
                    
                            if (null !== $key) {
                                $properties[$key] = $node->value($field);
                            }
                    
                            foreach ($cm->getLabeledProperties() as $labeledProperty) {
                                //$v = $node->hasLabel($labeledProperty->getLabelName()) ? true : false;
                                //$labeledProperty->setLabel($instance, $v);
                            }
                        }
                    }
                    */
                    foreach ($cm->getSimpleRelationships(false) as $relationship) {
                        if (!$relationship->isCollection()) {
                            $finder = new RelationshipsFinder($em, $relationship->getTargetEntity(), $relationship);
                            $instances = $finder->find($node->identity());
                            if (count($instances) > 0) {
                                $properties[ProxyUtils::getPropertyIdentifier($relationship->getReflectionProperty(), $cm->getClassName())] = $instances[0];
                            }
                        }
                    }
                    return true;
                };
            } else {
                $initializer = function ($ghostObject, $method, array $parameters, &$initializer) use($cm, $node, $em, $pmVersion) {
                    $initializer = null;
                    foreach ($cm->getPropertiesMetadata() as $field => $meta) {
                        if ($node->hasValue($field)) {
                            $meta->setValue($ghostObject, $node->value($field));
                        }
                    }
                    foreach ($cm->getSimpleRelationships(false) as $relationship) {
                        if (!$relationship->isCollection()) {
                            $finder = new RelationshipsFinder($em, $relationship->getTargetEntity(), $relationship);
                            $instances = $finder->find($node->identity());
                            if (count($instances) > 0) {
                                $relationship->setValue($ghostObject, $instances[0]);
                            }
                        }
                    }
                    $cm->setId($ghostObject, $node->identity());
                    return true;
                };
            }
            $proxyOptions = ['skippedProperties' => ['' . "" . '*' . "" . 'id']];
            $instance = 2 === $pmVersion ? $this->lazyLoadingFactory->createProxy($cm->getClassName(), $initializer, $proxyOptions) : $this->lazyLoadingFactory->createProxy($cm->getClassName(), $initializer);
            foreach ($cm->getPropertiesMetadata() as $field => $propertyMetadata) {
                if ($node->hasValue($field)) {
                    $propertyMetadata->setValue($instance, $node->value($field));
                }
            }
            $cm->setId($instance, $node->identity());
            foreach ($cm->getRelationships() as $relationship) {
                if (!$relationship->isRelationshipEntity()) {
                    if ($relationship->isCollection()) {
                        $lazyCollection = new LazyRelationshipCollection($this->entityManager, $instance, $relationship->getTargetEntity(), $relationship);
                        $relationship->setValue($instance, $lazyCollection);
                        continue;
                    }
                }
                if ($relationship->isRelationshipEntity()) {
                    if ($relationship->isCollection()) {
                        $lazyCollection = new LazyRelationshipCollection($this->entityManager, $instance, $relationship->getRelationshipEntityClass(), $relationship);
                        $relationship->setValue($instance, $lazyCollection);
                    } else {
                    }
                }
            }
            $i2 = clone $instance;
            $this->entityManager->getUnitOfWork()->addManaged($i2);
            return $i2;
        }
        $instance = $cm->newInstance();
        foreach ($cm->getPropertiesMetadata() as $field => $meta) {
            if ($meta instanceof EntityPropertyMetadata) {
                if ($node->hasValue($field)) {
                    $meta->setValue($instance, $node->value($field));
                }
            } elseif ($meta instanceof Label) {
                $label = $meta->name;
                /*
                $v = $node->hasLabel($label);
                if ($property = $reflClass->getProperty($field)) {
                    $property->setAccessible(true);
                    $property->setValue($instance, $v);
                }
                */
            }
        }
        foreach ($cm->getLabeledProperties() as $labeledProperty) {
            $v = $node->hasLabel($labeledProperty->getLabelName()) ? true : false;
            $labeledProperty->setLabel($instance, $v);
        }
        foreach ($cm->getRelationships() as $relationship) {
            if ($relationship->isCollection()) {
                $relationship->initializeCollection($instance);
            }
        }
        $cm->setId($instance, $node->identity());
        $this->entityManager->getUnitOfWork()->addManaged($instance);
        return $instance;
    }