/** * Hydrate a SpiderRecord from an OrientRecord * * @param $orientRecord * @return Response */ protected function mapOrientRecordToCollection(OrientRecord $orientRecord) { // Or we map a single record to a Spider Record $collection = new Collection($orientRecord->getOData()); $collection->add(['id' => $orientRecord->getRid()->jsonSerialize(), 'label' => $orientRecord->getOClass(), 'meta.rid' => $orientRecord->getRid(), 'meta.version' => $orientRecord->getVersion(), 'meta.oClass' => $orientRecord->getOClass()]); $collection->protect('id'); $collection->protect('label'); $collection->protect('meta'); return $collection; }
/** * @param $record * @return \stdClass * @throws \Exception */ protected function populateRecord(Record $record) { $classMap = $this->em->classMap; $key = $record->getOClass(); if (array_key_exists($key, $classMap)) { $entity = new $classMap[$key](); /* @var EntityInterface $entity */ $entity->setRid($record->getRid()); $oData = $record->getOData(); if (!empty($oData) && is_array($oData)) { foreach ($oData as $key => $value) { $entity->{$key} = $value; } } return $entity; } throw new Exception('Key not found'); }
public function extractRecord(Record &$record) { // prepair data: $rid = $record->getRid(); $recordData = $record->getOData(); $recordData['@rid'] = $this->IDtoRid($rid); $recordData['@version'] = $record->getVersion(); $recordData['@class'] = $record->getOClass(); foreach ($recordData as $key => $value) { if (is_a($value, 'DateTime')) { $value = $value->format('Y-m-d H:i:s'); $recordData[$key] = $value; } else { if (is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\Record')) { $recordData[$key] = $this->extractRecord($value); } else { if (is_array($value)) { $embeddedData = []; foreach ($value as $childRec) { // EMBEDDEDSET, EMBEDDEDLIST, EMBEDDEDMAP if (is_a($childRec, 'PhpOrient\\Protocols\\Binary\\Data\\Record')) { array_push($embeddedData, $this->extractRecord($childRec)); } else { // LINKSET, LINKLIST, LINKMAP if (is_a($childRec, 'PhpOrient\\Protocols\\Binary\\Data\\ID')) { $vortex = $this->findRelationByRid($childRec); if (!empty($vortex)) { array_push($embeddedData, $this->extractRecord($vortex)); } else { // not loaded array_push($embeddedData, $childRec); } } } } $recordData[$key] = $embeddedData; } else { if ($key !== '@rid' && is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\ID')) { $vortex = $this->findRelationByRid($value); if (!empty($vortex)) { $recordData[$key] = $this->extractRecord($vortex); } //??? convert to ActiveRecord } else { if (is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\Bag')) { $rids = $value->getRids(); foreach ($rids as $rid) { $relation = $this->findRelationByRid($rid); if (empty($relation)) { continue; } // relation not loaded if ($this->isEdge($relation)) { //? it always edge $edgeData = $relation->getOData(); $vortex = $this->findRelationByRid($edgeData['in']); $vortexData = $vortex->getOData(); // convert DateTime to ISO foreach ($vortexData as $vkey => $vval) { if (is_a($vval, 'DateTime')) { $vortexData[$vkey] = $vval->format('Y-m-d H:i:s'); } } $vortexData['@rid'] = $this->IDtoRid($vortex->getRid()); $vortexData['@version'] = $vortex->getVersion(); $vortexData['@class'] = $vortex->getOClass(); $vortexData['_edge'] = $this->IDtoRid($relation->getRid()); $recordData[$key] = $vortexData; } } } } } } } // continue; // if( !is_a($value, 'PhpOrient\Protocols\Binary\Data\Bag') // // && !is_a($value, 'PhpOrient\Protocols\Binary\Data\ID') // ) { // continue; // } } return $recordData; }