Skip to content

Commit

Permalink
Updated code to be compatible with php-etl/action-contracts:0.2
Browse files Browse the repository at this point in the history
gplanchat committed Nov 21, 2023
1 parent bee0c08 commit 8751e91
Showing 4 changed files with 95 additions and 166 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@
"prefer-stable": true,
"require": {
"php": "^8.2",
"php-etl/console-state": "*",
"php-etl/action-contracts": "0.2.*",
"php-etl/satellite-contracts": "0.1.*",
"symfony/console": "^6.0"
"symfony/console": "^6.0",
"php-etl/action": "*"
},
"autoload": {
"psr-4": {
201 changes: 45 additions & 156 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions src/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\Runtime\Action;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;

final class Action
{
/** @var array<string, callable> */
private array $metrics = [];
private readonly ConsoleSectionOutput $section;

public function __construct(
private readonly ConsoleOutput $output,
string $index,
string $label,
) {
$this->section = $this->output->section();
$this->section->writeln('');
$this->section->writeln(sprintf('<fg=green> % 2s. %-50s</>', $index, $label));
}

public function addMetric(string $label, callable $callback): self
{
$this->metrics[$label] = $callback;

return $this;
}

public function update(): void
{
$this->section
->writeln(' '.implode(', ', array_map(
fn (string $label, callable $callback) => sprintf('%s <fg=cyan>%s</>', $label, ($callback)()),
array_keys($this->metrics),
array_values($this->metrics),
)))
;
}
}
13 changes: 5 additions & 8 deletions src/Console.php
Original file line number Diff line number Diff line change
@@ -4,22 +4,22 @@

namespace Kiboko\Component\Runtime\Action;

use Kiboko\Component\State;
use Kiboko\Component\Action\ActionState;
use Kiboko\Contract\Action\ActionInterface;
use Kiboko\Contract\Action\ExecutingActionInterface;
use Kiboko\Contract\Action\StateInterface;
use Symfony\Component\Console\Output\ConsoleOutput;

final class Console implements ActionRuntimeInterface
{
private readonly State\StateOutput\Action $state;
private readonly Action $state;

public function __construct(
ConsoleOutput $output,
private readonly ExecutingActionInterface $action,
?State\StateOutput\Action $state = null
?Action $state = null
) {
$this->state = $state ?? new State\StateOutput\Action($output, 'A', 'Action');
$this->state = $state ?? new Action($output, 'A', 'Action');
}

public function execute(
@@ -28,10 +28,7 @@ public function execute(
): self {
$this->action->execute($action, $state = new ActionState($state));

$this->state
->addMetric('state', $state->observeState())
->addMetric('result', $state->observeResult())
;
$this->state->addMetric('state', $state->observeState());

return $this;
}

0 comments on commit 8751e91

Please sign in to comment.