@@ -81,13 +81,26 @@ public function constant(string $outputPath, $value): self
81
81
return $ this ;
82
82
}
83
83
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
+
84
97
public function expression (string $ outputPath , string |Expression $ expression , array $ additionalVariables = []): self
85
98
{
86
99
$ this ->fields [] = fn () => new FastMap \Mapping \Field (
87
100
new PropertyPath ($ outputPath ),
88
101
new FastMap \Mapping \Field \ExpressionLanguageValueMapper (
89
102
$ this ->interpreter ,
90
- $ expression instanceof Expression ? $ expression : new Expression ($ expression ),
103
+ $ this -> buildExpressionInstance ($ expression ),
91
104
$ additionalVariables ,
92
105
)
93
106
);
@@ -102,7 +115,7 @@ public function list(string $outputPath, string|Expression $expression): ArrayBu
102
115
$ this ->fields [] = fn () => new FastMap \Mapping \ListField (
103
116
new PropertyPath ($ outputPath ),
104
117
$ this ->interpreter ,
105
- $ expression instanceof Expression ? $ expression : new Expression ($ expression ),
118
+ $ this -> buildExpressionInstance ($ expression ),
106
119
$ child ->getMapper ()
107
120
);
108
121
@@ -128,7 +141,7 @@ public function object(string $outputPath, string $className, string|Expression
128
141
$ this ->fields [] = fn () => new FastMap \Mapping \SingleRelation (
129
142
new PropertyPath ($ outputPath ),
130
143
$ this ->interpreter ,
131
- $ expression instanceof Expression ? $ expression : new Expression ($ expression ),
144
+ $ this -> buildExpressionInstance ($ expression ),
132
145
$ child ->getMapper ()
133
146
);
134
147
@@ -142,7 +155,7 @@ public function collection(string $outputPath, string $className, string|Express
142
155
$ this ->fields [] = fn () => new FastMap \Mapping \MultipleRelation (
143
156
new PropertyPath ($ outputPath ),
144
157
$ this ->interpreter ,
145
- $ expression instanceof Expression ? $ expression : new Expression ($ expression ),
158
+ $ this -> buildExpressionInstance ($ expression ),
146
159
$ child ->getMapper ()
147
160
);
148
161
0 commit comments