Skip to content

Commit d0a37df

Browse files
authored
Merge pull request #5 from php-etl/feature/expression-language
Enable Expression Language for the expression field, added example co…
2 parents f7f97ea + 20199cf commit d0a37df

File tree

7 files changed

+92
-12
lines changed

7 files changed

+92
-12
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"php-etl/fast-map-config": "^0.3.0",
1919
"php-etl/configurator-contracts": "^0.3.0",
2020
"php-etl/packaging-contracts": "^0.1.0",
21-
"php-etl/fast-map": "^0.2.0"
21+
"php-etl/fast-map": "^0.2.0",
22+
"php-etl/satellite-toolbox": "^0.1.0"
2223
},
2324
"require-dev": {
2425
"php-etl/pipeline-contracts": "^0.1.0",

composer.lock

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fastmap:
2+
map:
3+
- field: '[sku]'
4+
copy: 'input[sku]'
5+
- field: '[title]'
6+
expression: 'input["sku"] ~" | "~ input["name"]'
7+
- field: '[name]'
8+
copy: '[name]'
9+
- field: '[staticValue]'
10+
constant: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mollis efficitur justo, id facilisis elit venenatis et. Sed fermentum posuere convallis. Phasellus lectus neque, bibendum sit amet enim imperdiet, dignissim blandit nisi. Donec nec neque nisi. Vivamus luctus facilisis nibh id rhoncus. Vestibulum eget facilisis tortor. Etiam at cursus enim, vitae mollis ex. Proin at velit at erat bibendum ultricies. Duis ut velit malesuada, placerat nisl a, ultrices tortor.'

src/Builder/ArrayMapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
final class ArrayMapper implements Builder
1010
{
1111
public function __construct(private ArrayBuilder $mapper)
12-
{}
12+
{
13+
}
1314

1415
public function getNode(): Node
1516
{

src/Builder/ObjectMapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
final class ObjectMapper implements Builder
1010
{
1111
public function __construct(private ObjectBuilder $mapper)
12-
{}
12+
{
13+
}
1314

1415
public function getNode(): Node
1516
{

src/Configuration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
66
use Symfony\Component\Config\Definition\ConfigurationInterface;
77
use Symfony\Component\Config\Definition\NodeInterface;
8+
use Symfony\Component\ExpressionLanguage\Expression;
89

910
final class Configuration implements ConfigurationInterface
1011
{
@@ -256,7 +257,11 @@ private function getChildTreeBuilder(string $name): TreeBuilder
256257
->children()
257258
->scalarNode('field')->isRequired()->end()
258259
->scalarNode('copy')->end()
259-
->scalarNode('expression')->end()
260+
->scalarNode('expression')
261+
->validate()
262+
->always(fn ($data) => new Expression($data))
263+
->end()
264+
->end()
260265
->scalarNode('constant')->end()
261266
->variableNode('map')
262267
->validate()

src/Configuration/ConfigurationApplier.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
final class ConfigurationApplier
99
{
1010
public function __construct(private array $additionalExpressionVariables = [])
11-
{}
11+
{
12+
}
1213

1314
public function __invoke(CompositeBuilderInterface $mapper, iterable $fields): void
1415
{
@@ -18,30 +19,30 @@ public function __invoke(CompositeBuilderInterface $mapper, iterable $fields): v
1819
$mapper->object($field['field'], $field['class'], $field['expression'])->children(),
1920
$field['object'],
2021
);
21-
} else if (array_key_exists('collection', $field)) {
22+
} elseif (array_key_exists('collection', $field)) {
2223
$this(
2324
$mapper->collection($field['field'], $field['class'], $field['expression'])->children(),
2425
$field['collection'],
2526
);
26-
} else if (array_key_exists('map', $field)) {
27+
} elseif (array_key_exists('map', $field)) {
2728
$this(
2829
$mapper->map($field['field'], $field['expression'])->children(),
2930
$field['map'],
3031
);
31-
} else if (array_key_exists('list', $field)) {
32+
} elseif (array_key_exists('list', $field)) {
3233
$this(
3334
$mapper->list($field['field'], $field['expression'])->children(),
3435
$field['list'],
3536
);
36-
} else if (array_key_exists('copy', $field)) {
37+
} elseif (array_key_exists('copy', $field)) {
3738
$mapper->copy($field['field'], $field['copy']);
38-
} else if (array_key_exists('expression', $field)) { // Should be at the end in order to let the complex fields use the "expression" property
39+
} elseif (array_key_exists('expression', $field)) { // Should be at the end in order to let the complex fields use the "expression" property
3940
$mapper->expression(
4041
$field['field'],
4142
$field['expression'],
4243
array_merge([], $field['variables'] ?? [], $this->additionalExpressionVariables),
4344
);
44-
} else if (array_key_exists('constant', $field)) {
45+
} elseif (array_key_exists('constant', $field)) {
4546
$mapper->constant($field['field'], $field['constant']);
4647
} else {
4748
throw new InvalidConfigurationException(sprintf(

0 commit comments

Comments
 (0)