public function on(EntityInterface $entity) : self { $exception = new self(sprintf('More than one relationship found on "%s::%s"', $entity->class(), $this->child->relationship()->property())); $exception->child = $this->child; $exception->entity = $entity; return $exception; }
/** * {@inheritdoc} */ public function make(IdentityInterface $identity, EntityInterface $meta, CollectionInterface $data) { if (!$meta instanceof Relationship) { throw new InvalidArgumentException(); } $reflection = (new ReflectionClass((string) $meta->class()))->withProperty($meta->identity()->property(), $identity)->withProperty($meta->startNode()->property(), $this->generators->get($meta->startNode()->type())->for($data->get($meta->startNode()->property())))->withProperty($meta->endNode()->property(), $this->generators->get($meta->endNode()->type())->for($data->get($meta->endNode()->property()))); $meta->properties()->foreach(function (string $name, Property $property) use(&$reflection, $data) { if ($property->type()->isNullable() && !$data->hasKey($name)) { return; } $reflection = $reflection->withProperty($name, $property->type()->fromDatabase($data->get($name))); }); return $reflection->buildObject(); }
/** * {@inheritdoc} */ public function make(IdentityInterface $identity, EntityInterface $meta, CollectionInterface $data) { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException(); } $reflection = (new ReflectionClass((string) $meta->class()))->withProperty($meta->identity()->property(), $identity); $meta->properties()->foreach(function (string $name, Property $property) use(&$reflection, $data) { if ($property->type()->isNullable() && !$data->hasKey($name)) { return; } $reflection = $reflection->withProperty($name, $property->type()->fromDatabase($data->get($name))); }); $meta->children()->foreach(function (string $property, ValueObject $meta) use(&$reflection, $data) { $reflection = $reflection->withProperty($property, $this->buildChild($meta, $data)); }); return $reflection->buildObject(); }