예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function translate(EntityInterface $meta, IdentityInterface $identity) : IdentityMatch
 {
     $query = (new Query())->match('entity', $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), '{entity_identity}')->withParameter('entity_identity', $identity->value())->with('entity');
     $variables = new Set('string');
     $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, &$variables) {
         $relName = (new Str('entity_'))->append($property);
         $childName = $relName->append('_')->append($child->relationship()->childProperty());
         $variables = $variables->add((string) $relName)->add((string) $childName);
         $query = $query->match('entity')->linkedTo((string) $childName, $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), (string) $relName, Relationship::LEFT);
     });
     return new IdentityMatch($query->return('entity', ...$variables->toPrimitive()), (new Map('string', EntityInterface::class))->put('entity', $meta));
 }
예제 #2
0
 /**
  * Add clause to match the node we want to delete and all of its children
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Query  $query
  *
  * @return Query
  */
 private function matchAggregate(IdentityInterface $identity, $entity, Query $query) : Query
 {
     $meta = $this->metadatas->get(get_class($entity));
     $name = $this->name->sprintf(md5($identity->value()));
     $this->variables = $this->variables->add((string) $name);
     $query = $query->match((string) $name, $meta->labels()->toPrimitive())->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value());
     $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, $name) {
         $query = $query->match((string) $name)->linkedTo($childName = (string) $name->append('_')->append($child->relationship()->property())->append('_')->append($child->relationship()->childProperty()), $child->labels()->toPrimitive())->through((string) $child->relationship()->type(), $relName = (string) $name->append('_')->append($child->relationship()->property()));
         $this->variables = $this->variables->add($childName)->add($relName);
     });
     return $query;
 }
예제 #3
0
 /**
  * Add the clause to create a relationship between nodes
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Query $query
  *
  * @return Query
  */
 private function createRelationship(IdentityInterface $identity, $entity, Query $query) : Query
 {
     $meta = $this->metadatas->get(get_class($entity));
     $data = $this->extractor->extract($entity);
     $start = $data->get($meta->startNode()->property());
     $end = $data->get($meta->endNode()->property());
     $varName = $this->name->sprintf(md5($identity->value()));
     $startName = $this->name->sprintf(md5($start));
     $endName = $this->name->sprintf(md5($end));
     $paramKey = $varName->append('_props');
     $properties = $this->buildProperties($meta->properties(), $paramKey);
     return $this->matchEdge($endName, $meta->endNode(), $end, $this->matchEdge($startName, $meta->startNode(), $start, $query))->create((string) $startName)->linkedTo((string) $endName)->through((string) $meta->type(), (string) $varName, DBALRelationship::RIGHT)->withProperty($meta->identity()->property(), (string) $paramKey->prepend('{')->append('}.')->append($meta->identity()->property()))->withProperties($properties->toPrimitive())->withParameters([(string) $paramKey => $data->keyIntersect($properties)->set($meta->identity()->property(), $identity->value())->toPrimitive()]);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function translate(EntityInterface $meta, IdentityInterface $identity) : IdentityMatch
 {
     $query = (new Query())->match('start')->linkedTo('end')->through((string) $meta->type(), 'entity', Relationship::RIGHT)->withProperty($meta->identity()->property(), '{entity_identity}')->withParameter('entity_identity', $identity->value())->return('start', 'end', 'entity');
     return new IdentityMatch($query, (new Map('string', EntityInterface::class))->put('entity', $meta));
 }
예제 #5
0
 /**
  * Add the match clause for a relationship
  *
  * @param IdentityInterface $identity
  * @param object $entity
  * @param Relationship $meta
  * @param CollectionInterface $changeset
  * @param Query $query
  *
  * @return Query
  */
 private function matchRelationship(IdentityInterface $identity, $entity, Relationship $meta, CollectionInterface $changeset, Query $query) : Query
 {
     $name = $this->name->sprintf(md5($identity->value()));
     $this->variables = $this->variables->put($name, $this->buildProperties($changeset, $meta->properties()));
     return $query->match()->linkedTo()->through((string) $meta->type(), (string) $name)->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value());
 }