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; }
/** * {@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; }
/** * Return a new instance of the class * * @return object */ public function buildObject() { $object = $this->instanciator->build($this->class, $this->properties); $parameters = $this->instanciator->getParameters($this->class); //avoid injecting the properties already used in the constructor $properties = $this->properties->filter(function ($value, $property) use($parameters) { return !$parameters->contains($property); }); $refl = new ReflectionObject($object, $properties, $this->injectionStrategies); return $refl->buildObject(); }