File size: 1,610 Bytes
4202035
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\FeatureFlags\Commands;

use Piwik\Container\StaticContainer;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\FeatureFlags\Commands\FeatureFlagFinder\FeatureFlagFinder;
use Piwik\Plugins\FeatureFlags\FeatureFlagManager;
use Piwik\Plugins\FeatureFlags\ForcedFeatureFlagStateInterface;

class ListFeatureFlags extends ConsoleCommand
{
    protected function configure()
    {
        $this->setName('featureflags:list');
        $this->setDescription('List all available feature flags and their current state');
    }

    protected function doExecute(): int
    {
        $featureFlagManager = StaticContainer::get(FeatureFlagManager::class);

        $rows = [];
        foreach (FeatureFlagFinder::findAll() as $featureFlag) {
            $state = $featureFlagManager->isFeatureActive(get_class($featureFlag)) ? 'enabled' : 'disabled';

            if ($featureFlag instanceof ForcedFeatureFlagStateInterface) {
                $state .= ' (forced)';
            }

            $rows[] = [$featureFlag->getName(), get_class($featureFlag), $state];
        }

        if (empty($rows)) {
            $this->getOutput()->writeln('No feature flags found.');
            return self::SUCCESS;
        }

        usort($rows, static function (array $a, array $b): int {
            return strcmp($a[0], $b[0]);
        });

        $this->renderTable(['Name', 'Class', 'State'], $rows);

        return self::SUCCESS;
    }
}