/** * {@inheritdoc} */ public function make(CollectionInterface $config) : EntityInterface { $entity = new Relationship(new ClassName($config->get('class')), new Identity($config->get('identity')['property'], $config->get('identity')['type']), new Repository($config->hasKey('repository') ? $config->get('repository') : EntityRepository::class), new Factory($config->hasKey('factory') ? $config->get('factory') : EntityFactory::class), new Alias($config->hasKey('alias') ? $config->get('alias') : $config->get('class')), new RelationshipType($config->get('rel_type')), new RelationshipEdge($config->get('startNode')['property'], $config->get('startNode')['type'], $config->get('startNode')['target']), new RelationshipEdge($config->get('endNode')['property'], $config->get('endNode')['type'], $config->get('endNode')['target'])); if ($config->hasKey('properties')) { $entity = $this->appendProperties($entity, new Collection($config->get('properties'))); } return $entity; }
/** * {@inheritdoc} */ public function make(CollectionInterface $config) : EntityInterface { $entity = new Aggregate(new ClassName($config->get('class')), new Identity($config->get('identity')['property'], $config->get('identity')['type']), new Repository($config->hasKey('repository') ? $config->get('repository') : EntityRepository::class), new Factory($config->hasKey('factory') ? $config->get('factory') : EntityFactory::class), new Alias($config->hasKey('alias') ? $config->get('alias') : $config->get('class')), $config->get('labels')); if ($config->hasKey('properties')) { $entity = $this->appendProperties($entity, new Collection($config->get('properties'))); } if ($config->hasKey('children')) { $entity = $this->appendChildren($entity, new Collection($config->get('children'))); } return $entity; }
/** * {@inheritdoc} */ public static function fromConfig(CollectionInterface $config) : TypeInterface { $type = new self(); if ($config->hasKey('nullable')) { $type->nullable = true; } if ($config->hasKey('format')) { $type->format = $config->get('format'); } if ($config->hasKey('immutable')) { $type->immutable = (bool) $config->get('immutable'); } return $type; }
/** * {@inheritdoc} */ public static function fromConfig(CollectionInterface $config) : TypeInterface { $type = new self(); if (!$config->hasKey('inner')) { throw TypeDeclarationException::missingField('inner'); } if (self::identifiers()->contains($config->get('inner'))) { throw new RecursiveTypeDeclarationException(); } $type->inner = $config->get('_types')->build($config->get('inner'), $config->unset('inner')->unset('_types')); if ($config->hasKey('nullable')) { $type->nullable = true; } return $type; }
private function diff(CollectionInterface $source, CollectionInterface $target) : CollectionInterface { $changeset = new Collection([]); $target->each(function (string $property, $value) use(&$changeset, $source) { if (!$source->hasKey($property) || $value !== $source->get($property)) { $changeset = $changeset->set($property, $value); } }); $source->each(function (string $property) use(&$changeset, $target) { if (!$target->hasKey($property)) { $changeset = $changeset->set($property, null); } }); $changeset->each(function (string $property, $value) use(&$changeset, $source, $target) { if (!$value instanceof CollectionInterface) { return; } $changeset = $changeset->set($property, $this->diff($source->get($property), $target->get($property))); }); $changeset = $changeset->filter(function ($value) { if (!$value instanceof CollectionInterface) { return true; } return $value->count() !== 0; }); return $changeset; }
/** * {@inheritdoc} */ public static function fromConfig(CollectionInterface $config) : TypeInterface { $type = new self(); if ($config->hasKey('nullable')) { $type->nullable = true; } return $type; }
private function buildValueObject(ValueObject $meta, CollectionInterface $data) { $reflection = new ReflectionClass((string) $meta->class()); $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(); }