This repository was archived by the owner on Oct 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDebugFlagsCommand.php
More file actions
78 lines (60 loc) · 2.27 KB
/
DebugFlagsCommand.php
File metadata and controls
78 lines (60 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace DZunke\FeatureFlagsBundle\Command;
use DZunke\FeatureFlagsBundle\Toggle;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DebugFlagsCommand extends Command
{
public function __construct(private readonly Toggle $toggle, private readonly Toggle\ConditionBag $conditionBag)
{
parent::__construct();
}
protected function configure(): void
{
$this
->setName('dzunke:feature_flags:debug')
->setDescription('Debugging Feature Flags');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('');
$output->writeln('<fg=cyan>Debugging Feature Flags</fg=cyan>');
$output->writeln('<fg=cyan>=======================</fg=cyan>');
$output->writeln('');
$output->writeln('<fg=cyan>Existing Flag-Conditions</fg=cyan>');
$output->writeln('<fg=cyan>------------------------</fg=cyan>');
$output->writeln('');
$table = new Table($output);
$table->setStyle('borderless');
$table->setHeaders(['name', 'class']);
foreach ($this->conditionBag as $name => $condition) {
$table->addRow([$name, $condition::class]);
}
$table->render();
$output->writeln('');
$output->writeln('<fg=cyan>Configured Feature-Flags</fg=cyan>');
$output->writeln('<fg=cyan>------------------------</fg=cyan>');
$output->writeln('');
$this->renderFlagsTable($output);
$output->writeln('');
return 0;
}
private function renderFlagsTable(OutputInterface $output): void
{
$flags = $this->toggle->getFlags();
if (empty($flags)) {
$output->writeln('<comment> ! [NOTE] there are no flags configured</comment>');
return;
}
ksort($flags);
$table = new Table($output);
$table->setStyle('borderless');
$table->setHeaders(['name', 'conditions']);
foreach ($flags as $name => $flag) {
$table->addRow([$name, implode(', ', array_keys($flag->getConfig()))]);
}
$table->render();
}
}