/** * {@inheritdoc} */ public function translate(EntityInterface $meta, SpecificationInterface $specification) : IdentityMatch { $variables = new Set('string'); try { $mapping = (new AggregatePropertyMatchVisitor($meta))->visit($specification); $query = $this->addProperties((new Query())->match('entity', $meta->labels()->toPrimitive()), 'entity', $mapping)->with('entity'); $meta->children()->foreach(function (string $property, ValueObject $child) use(&$query, $mapping, &$variables) { $relName = (new Str('entity_'))->append($property); $childName = $relName->append('_')->append($child->relationship()->childProperty()); $variables = $variables->add((string) $relName)->add((string) $childName); $query = $this->addProperties($this->addProperties($query->match('entity')->linkedTo((string) $childName, $child->labels()->toPrimitive()), (string) $childName, $mapping)->through((string) $child->relationship()->type(), (string) $relName, Relationship::LEFT), (string) $relName, $mapping); }); } catch (SpecificationNotApplicableAsPropertyMatchException $e) { $query = (new Query())->match('entity', $meta->labels()->toPrimitive())->with('entity'); $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); }); $condition = (new AggregateCypherVisitor($meta))->visit($specification); $query = $query->where($condition->get(0))->withParameters($condition->get(1)->toPrimitive()); } return new IdentityMatch($query->return('entity', ...$variables->toPrimitive()), (new Map('string', EntityInterface::class))->put('entity', $meta)); }
/** * {@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)); }