Skip to content

Commit a2f6e0a

Browse files
authored
Merge pull request #15 from php-etl/feature/constant-mapper
Enabled several types (boolean, int, string) for the constant mapper
2 parents 5f8a000 + aaaa634 commit a2f6e0a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Mapping/Field/ConstantValueMapper.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,30 @@ public function compile(Node\Expr $outputNode): array
4747
new Node\Stmt\Expression(
4848
new Node\Expr\Assign(
4949
$outputNode,
50-
new Node\Scalar\String_($this->value)
50+
$this->compileValue($this->value)
5151
),
5252
),
5353
];
5454
}
55+
56+
public function compileValue(mixed $value): Node\Expr
57+
{
58+
if ($value === true) {
59+
return new Node\Expr\ConstFetch(
60+
name: new Node\Name(name: 'true'),
61+
);
62+
}
63+
64+
if ($value === false) {
65+
return new Node\Expr\ConstFetch(
66+
name: new Node\Name(name: 'false'),
67+
);
68+
}
69+
70+
if (is_int($value)) {
71+
return new Node\Scalar\LNumber(value: $value);
72+
}
73+
74+
return new Node\Scalar\String_(value: $value);
75+
}
5576
}

0 commit comments

Comments
 (0)