/** * {@inheritdoc} */ public function extract($entity, EntityInterface $meta) : CollectionInterface { if (!$meta instanceof Relationship) { throw new InvalidArgumentException(); } $refl = new ReflectionObject($entity); $data = $refl->extract([$id = $meta->identity()->property(), $start = $meta->startNode()->property(), $end = $meta->endNode()->property()]); $data = $data->set($id, $data->get($id)->value())->set($start, $data->get($start)->value())->set($end, $data->get($end)->value()); $meta->properties()->foreach(function (string $name, Property $property) use(&$data, $refl) { $data = $data->set($name, $property->type()->forDatabase($refl->extract([$name])->get($name))); }); return $data; }
private function extractProperties($object, MapInterface $properties) : CollectionInterface { $refl = new ReflectionObject($object); $data = new Collection([]); $properties->foreach(function (string $name, Property $property) use(&$data, $refl) { $data = $data->set($name, $property->type()->forDatabase($refl->extract([$name])->get($name))); }); return $data; }