Doctrine\ODM\OrientDB\Mapper\Hydration\Hydrator::hydrate PHP Method

hydrate() public method

If the class is found, a new POPO is instantiated and the properties inside the JSON object are filled accordingly.
public hydrate ( stdClass $orientObject, Doctrine\ODM\OrientDB\Proxy\Proxy $proxy = null ) : Result
$orientObject stdClass
$proxy Doctrine\ODM\OrientDB\Proxy\Proxy
return Result
    public function hydrate(\stdClass $orientObject, Proxy $proxy = null)
    {
        $classProperty = static::ORIENT_PROPERTY_CLASS;
        if ($proxy) {
            $this->fill($proxy, $orientObject);
            return $proxy;
        } elseif (property_exists($orientObject, $classProperty)) {
            $orientClass = $orientObject->{$classProperty};
            if ($orientClass) {
                $class = $this->getMetadataFactory()->findClassMappingInDirectories($orientClass);
                $document = $this->createDocument($class, $orientObject);
                return $document;
            }
            throw new DocumentNotFoundException(self::ORIENT_PROPERTY_CLASS . ' property empty.');
        }
        throw new DocumentNotFoundException(self::ORIENT_PROPERTY_CLASS . ' property not found.');
    }

Usage Example

Example #1
0
 /**
  * Generates a closure capable of finalizing a cloned proxy
  *
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $classMetadata
  * @param \ReflectionProperty $reflectionId
  *
  * @return \Closure
  *
  * @throws \Doctrine\ODM\OrientDB\DocumentNotFoundException
  */
 private function createCloner(BaseClassMetadata $classMetadata, Hydrator $hydrator, \ReflectionProperty $reflectionId)
 {
     return function (BaseProxy $proxy) use($reflectionId, $hydrator, $classMetadata) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         $rid = $reflectionId->getValue($proxy);
         $original = $hydrator->load(array($rid));
         if (null === $original) {
             throw DocumentNotFoundException::documentNotFound(get_class($proxy), $rid);
         }
         $original = $hydrator->hydrate($original[0], $proxy);
         foreach ($classMetadata->getReflectionClass()->getProperties() as $reflectionProperty) {
             $propertyName = $reflectionProperty->getName();
             if ($classMetadata->hasField($propertyName) || $classMetadata->hasAssociation($propertyName)) {
                 $reflectionProperty->setAccessible(true);
                 $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($original));
             }
         }
     };
 }