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
  • Loading branch information
gplanchat committed Nov 21, 2023
1 parent bee0c08 commit 8751e91
Show file tree
Hide file tree
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
Expand Up @@ -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": {
Expand Down
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),
)))
;
}
}
Loading

0 comments on commit 8751e91

Please sign in to comment.