Skip to content

Commit 978bea0

Browse files
authored
Fixed expressions prefix management
1 parent 56d57c5 commit 978bea0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/CompositeBuilder.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,26 @@ public function constant(string $outputPath, $value): self
8181
return $this;
8282
}
8383

84+
private function buildExpressionInstance(string|Expression $expression): Expression
85+
{
86+
if ($expression instanceof Expression) {
87+
return $expression;
88+
}
89+
90+
if (strpos($expression, '@=') === 0) {
91+
$expression = substr($expression, 2);
92+
}
93+
94+
return new Expression($expression);
95+
}
96+
8497
public function expression(string $outputPath, string|Expression $expression, array $additionalVariables = []): self
8598
{
8699
$this->fields[] = fn () => new FastMap\Mapping\Field(
87100
new PropertyPath($outputPath),
88101
new FastMap\Mapping\Field\ExpressionLanguageValueMapper(
89102
$this->interpreter,
90-
$expression instanceof Expression ? $expression : new Expression($expression),
103+
$this->buildExpressionInstance($expression),
91104
$additionalVariables,
92105
)
93106
);
@@ -102,7 +115,7 @@ public function list(string $outputPath, string|Expression $expression): ArrayBu
102115
$this->fields[] = fn () => new FastMap\Mapping\ListField(
103116
new PropertyPath($outputPath),
104117
$this->interpreter,
105-
$expression instanceof Expression ? $expression : new Expression($expression),
118+
$this->buildExpressionInstance($expression),
106119
$child->getMapper()
107120
);
108121

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

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

0 commit comments

Comments
 (0)