Example #1
0
 /**
  * Hydrate a Collection from an Neo4J Node
  *
  * @param \Everyman\Neo4j\Node $row a single row from result set to map.
  * @return Collection
  */
 protected function nodeToCollection(\EveryMan\Neo4j\Node $row)
 {
     // Or we map a single record to a Spider Record
     $collection = new Collection();
     foreach ($row->getProperties() as $key => $value) {
         $collection->add($key, $value);
     }
     //handle labels
     $labels = $row->getLabels();
     if (!empty($labels)) {
         $collection->add(['meta.label' => $labels[0]->getName(), 'label' => $labels[0]->getName()]);
     }
     $collection->add(['meta.id' => $row->getId(), 'id' => $row->getId()]);
     $collection->protect('meta');
     $collection->protect('id');
     $collection->protect('label');
     return $collection;
 }
Example #2
0
 /**
  * Hydrate a Collection from an Gremlin response
  *
  * @param array $row a single row from result set to map.
  *
  * @return Collection
  */
 protected function arrayToCollection(array $row)
 {
     // Or we map a single record to a Spider Record
     $collection = new Collection();
     //If we're in a classic vertex/edge scenario lets do the following:
     if (isset($row['properties'])) {
         foreach ($row['properties'] as $key => $value) {
             $collection->add($key, $value[0]['value']);
         }
         foreach ($row as $key => $value) {
             if ($key != "properties") {
                 $collection->add('meta.' . $key, $value);
             }
         }
         $collection->add(['id' => $collection->meta()->id, 'label' => $collection->meta()->label]);
         $collection->protect('id');
         $collection->protect('label');
         $collection->protect('meta');
     } else {
         //in any other situation lets just map directly to the collection.
         $collection->add($row);
     }
     return $collection;
 }
Example #3
0
 /**
  * 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;
 }