/** * {@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; }
private function makeEntity(EntityInterface $meta, CollectionInterface $data) { $identity = $this->generators->get($meta->identity()->type())->for($data->get($meta->identity()->property())); if ($this->entities->contains($identity)) { return $this->entities->get($identity); } $entity = $this->resolver->get($meta)->make($identity, $meta, $data); $this->entities = $this->entities->push($identity, $entity, Container::STATE_MANAGED); return $entity; }
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(); }
/** * Add the cypher clause to build the relationship and the node corresponding * to a child of the aggregate * * @param ValueObject $meta * @param Str $nodeName * @param CollectionInterface $data * @param Query $query * * @return Query */ private function createAggregateChild(ValueObject $meta, Str $nodeName, CollectionInterface $data, Query $query) : Query { $relationshipName = $nodeName->append('_')->append($meta->relationship()->property()); $endNodeName = $relationshipName->append('_')->append($meta->relationship()->childProperty()); $endNodeProperties = $this->buildProperties($meta->properties(), $endNodeParamKey = $endNodeName->append('_props')); $relationshipProperties = $this->buildProperties($meta->relationship()->properties(), $relationshipParamKey = $relationshipName->append('_props')); return $query->create((string) $nodeName)->linkedTo((string) $endNodeName, $meta->labels()->toPrimitive())->withProperties($endNodeProperties->toPrimitive())->withParameters([(string) $endNodeParamKey => $data->get($meta->relationship()->childProperty())->toPrimitive()])->through((string) $meta->relationship()->type(), (string) $relationshipName, DBALRelationship::LEFT)->withProperties($relationshipProperties->toPrimitive())->withParameters([(string) $relationshipParamKey => $data->unset($meta->relationship()->childProperty())->toPrimitive()]); }
/** * This method returns current item in collection based on currentIndex. * @return mixed */ public function current() { return $this->collection->get($this->key()); }
/** * {@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; }