Skip to content

Commit 8751e91

Browse files
committed
Updated code to be compatible with php-etl/action-contracts:0.2
1 parent bee0c08 commit 8751e91

File tree

4 files changed

+95
-166
lines changed

4 files changed

+95
-166
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"prefer-stable": true,
1818
"require": {
1919
"php": "^8.2",
20-
"php-etl/console-state": "*",
2120
"php-etl/action-contracts": "0.2.*",
2221
"php-etl/satellite-contracts": "0.1.*",
23-
"symfony/console": "^6.0"
22+
"symfony/console": "^6.0",
23+
"php-etl/action": "*"
2424
},
2525
"autoload": {
2626
"psr-4": {

composer.lock

Lines changed: 45 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Action.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Runtime\Action;
6+
7+
use Symfony\Component\Console\Output\ConsoleOutput;
8+
use Symfony\Component\Console\Output\ConsoleSectionOutput;
9+
10+
final class Action
11+
{
12+
/** @var array<string, callable> */
13+
private array $metrics = [];
14+
private readonly ConsoleSectionOutput $section;
15+
16+
public function __construct(
17+
private readonly ConsoleOutput $output,
18+
string $index,
19+
string $label,
20+
) {
21+
$this->section = $this->output->section();
22+
$this->section->writeln('');
23+
$this->section->writeln(sprintf('<fg=green> % 2s. %-50s</>', $index, $label));
24+
}
25+
26+
public function addMetric(string $label, callable $callback): self
27+
{
28+
$this->metrics[$label] = $callback;
29+
30+
return $this;
31+
}
32+
33+
public function update(): void
34+
{
35+
$this->section
36+
->writeln(' '.implode(', ', array_map(
37+
fn (string $label, callable $callback) => sprintf('%s <fg=cyan>%s</>', $label, ($callback)()),
38+
array_keys($this->metrics),
39+
array_values($this->metrics),
40+
)))
41+
;
42+
}
43+
}

0 commit comments

Comments
 (0)