Skip to content

Commit

Permalink
Improved the Pipeline builder to add a stepCode on each method of the…
Browse files Browse the repository at this point in the history
… runtime + made the step code required in the configuration
  • Loading branch information
sebprt committed Nov 14, 2023
1 parent 247b399 commit 51b0fab
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Builder/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct(
) {}

public function addExtractor(
Node\Expr|Builder $stepCode,
Node\Expr|Builder $extractor,
Node\Expr|Builder $rejection,
Node\Expr|Builder $state,
Expand All @@ -24,6 +25,7 @@ public function addExtractor(
var: $runtime,
name: new Node\Identifier('extract'),
args: [
new Node\Arg($stepCode instanceof Builder ? $stepCode->getNode() : $stepCode),
new Node\Arg($extractor instanceof Builder ? $extractor->getNode() : $extractor),
new Node\Arg($rejection instanceof Builder ? $rejection->getNode() : $rejection),
new Node\Arg($state instanceof Builder ? $state->getNode() : $state),
Expand All @@ -34,6 +36,7 @@ public function addExtractor(
}

public function addTransformer(
Node\Expr|Builder $stepCode,
Node\Expr|Builder $transformer,
Node\Expr|Builder $rejection,
Node\Expr|Builder $state,
Expand All @@ -42,6 +45,7 @@ public function addTransformer(
var: $runtime,
name: new Node\Identifier('transform'),
args: [
new Node\Arg($stepCode instanceof Builder ? $stepCode->getNode() : $stepCode),
new Node\Arg($transformer instanceof Builder ? $transformer->getNode() : $transformer),
new Node\Arg($rejection instanceof Builder ? $rejection->getNode() : $rejection),
new Node\Arg($state instanceof Builder ? $state->getNode() : $state),
Expand All @@ -52,6 +56,7 @@ public function addTransformer(
}

public function addLoader(
Node\Expr|Builder $stepCode,
Node\Expr|Builder $loader,
Node\Expr|Builder $rejection,
Node\Expr|Builder $state,
Expand All @@ -60,6 +65,7 @@ public function addLoader(
var: $runtime,
name: new Node\Identifier('load'),
args: [
new Node\Arg($stepCode instanceof Builder ? $stepCode->getNode() : $stepCode),
new Node\Arg($loader instanceof Builder ? $loader->getNode() : $loader),
new Node\Arg($rejection instanceof Builder ? $rejection->getNode() : $rejection),
new Node\Arg($state instanceof Builder ? $state->getNode() : $state),
Expand Down
1 change: 1 addition & 0 deletions src/Pipeline/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterf
}

$pipeline->addExtractor(
new Node\Scalar\String_($config['code']),
$repository->getBuilder()
->withLogger($logger)
->withRejection($rejection)
Expand Down
1 change: 1 addition & 0 deletions src/Pipeline/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterf
}

$pipeline->addLoader(
new Node\Scalar\String_($config['code']),
$repository->getBuilder()
->withLogger($logger)
->withRejection($rejection)
Expand Down
1 change: 1 addition & 0 deletions src/Pipeline/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterf
}

$pipeline->addTransformer(
new Node\Scalar\String_($config['code']),
$repository->getBuilder()
->withLogger($logger)
->withRejection($rejection)
Expand Down
24 changes: 15 additions & 9 deletions src/Runtime/Pipeline/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function getStepsTreeBuilder(): TreeBuilder
->isRequired()
->fixXmlConfig('step')
->validate()
->ifTrue(fn ($value) => 1 <= array_reduce(
array_keys($this->plugins),
fn (int $count, string $plugin) => \array_key_exists($plugin, $value) ? $count + 1 : $count,
0
))
->thenInvalid(sprintf('You should only specify one plugin between %s.', implode('", "', array_map(fn (string $plugin) => sprintf('"%s"', $plugin), array_keys($this->plugins)))))
->ifTrue(fn ($value) => 1 <= array_reduce(
array_keys($this->plugins),
fn (int $count, string $plugin) => \array_key_exists($plugin, $value) ? $count + 1 : $count,
0
))
->thenInvalid(sprintf('You should only specify one plugin between %s.', implode('", "', array_map(fn (string $plugin) => sprintf('"%s"', $plugin), array_keys($this->plugins)))))
->end()
;

Expand All @@ -80,7 +80,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarPrototype()->end()
->end()
->scalarNode('name')->end()
->scalarNode('code')->end()
->scalarNode('code')
->isRequired()
->end()
->append($this->getStepsTreeBuilder()->getRootNode())
->end()
;
Expand All @@ -95,7 +97,9 @@ private function applyPlugins(ArrayNodeDefinition $node): self
$node
->children()
->scalarNode('name')->end()
->scalarNode('code')->end()
->scalarNode('code')
->isRequired()
->end()
->end()
->append($plugin->getConfigTreeBuilder()->getRootNode())
;
Expand All @@ -110,7 +114,9 @@ private function applyFeatures(ArrayNodeDefinition $node): self
/* @phpstan-ignore-next-line */
$node->children()
->scalarNode('name')->end()
->scalarNode('code')->end()
->scalarNode('code')
->isRequired()
->end()
->end()
->append($feature->getConfigTreeBuilder()->getRootNode())
;
Expand Down
9 changes: 8 additions & 1 deletion src/Runtime/Workflow/Action/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public function getConfigTreeBuilder(): TreeBuilder
$builder = new TreeBuilder('action');

/** @var ArrayNodeDefinition $node */
$node = $builder->getRootNode();
$node = $builder->getRootNode()

Check failure on line 29 in src/Runtime/Workflow/Action/Configuration.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children().
->children()
->scalarNode('name')->end()
->scalarNode('code')
->isRequired()
->end()
->end()
;

foreach ($this->actions as $action) {
$node->append($action->getConfigTreeBuilder()->getRootNode());
Expand Down
4 changes: 2 additions & 2 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ private function compilePipelineJob(array $config): Satellite\Builder\Repository
$repository = new Satellite\Builder\Repository\Pipeline($pipeline);

$repository->addPackages(
'php-etl/pipeline-contracts:0.4.*',
'php-etl/pipeline:*',
'php-etl/pipeline-contracts:dev-main',
'php-etl/pipeline:dev-main',
'php-etl/console-state:*',
'php-etl/pipeline-console-runtime:*',
'php-etl/workflow-console-runtime:*',
Expand Down

0 comments on commit 51b0fab

Please sign in to comment.