Skip to content

Commit

Permalink
Fixed expressions prefix management
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat authored Dec 3, 2024
1 parent 56d57c5 commit 978bea0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/CompositeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,26 @@ public function constant(string $outputPath, $value): self
return $this;
}

private function buildExpressionInstance(string|Expression $expression): Expression
{
if ($expression instanceof Expression) {
return $expression;
}

if (strpos($expression, '@=') === 0) {
$expression = substr($expression, 2);
}

return new Expression($expression);
}

public function expression(string $outputPath, string|Expression $expression, array $additionalVariables = []): self
{
$this->fields[] = fn () => new FastMap\Mapping\Field(
new PropertyPath($outputPath),
new FastMap\Mapping\Field\ExpressionLanguageValueMapper(
$this->interpreter,
$expression instanceof Expression ? $expression : new Expression($expression),
$this->buildExpressionInstance($expression),
$additionalVariables,
)
);
Expand All @@ -102,7 +115,7 @@ public function list(string $outputPath, string|Expression $expression): ArrayBu
$this->fields[] = fn () => new FastMap\Mapping\ListField(
new PropertyPath($outputPath),
$this->interpreter,
$expression instanceof Expression ? $expression : new Expression($expression),
$this->buildExpressionInstance($expression),
$child->getMapper()
);

Expand All @@ -128,7 +141,7 @@ public function object(string $outputPath, string $className, string|Expression
$this->fields[] = fn () => new FastMap\Mapping\SingleRelation(
new PropertyPath($outputPath),
$this->interpreter,
$expression instanceof Expression ? $expression : new Expression($expression),
$this->buildExpressionInstance($expression),
$child->getMapper()
);

Expand All @@ -142,7 +155,7 @@ public function collection(string $outputPath, string $className, string|Express
$this->fields[] = fn () => new FastMap\Mapping\MultipleRelation(
new PropertyPath($outputPath),
$this->interpreter,
$expression instanceof Expression ? $expression : new Expression($expression),
$this->buildExpressionInstance($expression),
$child->getMapper()
);

Expand Down

0 comments on commit 978bea0

Please sign in to comment.