Skip to content

Commit 0ff89f3

Browse files
pjcdawkinsclaude
andcommitted
Fix PHP 5.6 compatibility and remove Selector dependency.
This adjusts the backport to work with the 4.x codebase: - Convert all metrics commands to use CommandBase methods instead of the Selector class - Remove constructor dependencies and use service locator pattern via getService() - Use filterEnvsMaybeActive(), validateInput(), and getSelectedEnvironment() for environment selection - Remove CurlCommand reference from Application.php (command was deleted in backport) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent dab8bb3 commit 0ff89f3

File tree

6 files changed

+27
-173
lines changed

6 files changed

+27
-173
lines changed

src/Application.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ protected function getCommands()
202202
$commands[] = new Command\Organization\User\OrganizationUserUpdateCommand();
203203
$commands[] = new Command\Metrics\AllMetricsCommand();
204204
$commands[] = new Command\Metrics\CpuCommand();
205-
$commands[] = new Command\Metrics\CurlCommand();
206205
$commands[] = new Command\Metrics\DiskUsageCommand();
207206
$commands[] = new Command\Metrics\MemCommand();
208207
$commands[] = new Command\Project\ProjectClearBuildCacheCommand();

src/Command/Metrics/AllMetricsCommand.php

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Platformsh\Cli\Model\Metrics\MetricKind;
88
use Platformsh\Cli\Model\Metrics\SourceField;
99
use Platformsh\Cli\Model\Metrics\SourceFieldPercentage;
10-
use Platformsh\Cli\Selector\SelectorConfig;
11-
use Platformsh\Cli\Selector\Selector;
1210
use Khill\Duration\Duration;
1311
use Platformsh\Cli\Service\PropertyFormatter;
1412
use Platformsh\Cli\Service\Table;
@@ -67,24 +65,6 @@ class AllMetricsCommand extends MetricsCommandBase
6765
'tmp_inodes_percent',
6866
);
6967

70-
/**
71-
* @var PropertyFormatter
72-
*/
73-
private $propertyFormatter;
74-
75-
/**
76-
* @param PropertyFormatter $propertyFormatter
77-
* @param Selector $selector
78-
* @param Table $table
79-
*/
80-
public function __construct(
81-
PropertyFormatter $propertyFormatter,
82-
Selector $selector,
83-
Table $table
84-
) {
85-
$this->propertyFormatter = $propertyFormatter;
86-
parent::__construct($selector, $table);
87-
}
8868

8969
/**
9070
* {@inheritdoc}
@@ -98,22 +78,11 @@ protected function configure()
9878
$this->addExample('Show metrics for the last ' . (new Duration())->humanize(self::DEFAULT_RANGE));
9979
$this->addExample('Show metrics over the last hour', ' -r 1h');
10080
$this->addExample('Show metrics for all SQL services', '--type mariadb,%sql');
101-
$this->addMetricsOptions();
102-
$this->selector->addProjectOption($this->getDefinition());
103-
$this->selector->addEnvironmentOption($this->getDefinition());
104-
$this->addCompleter($this->selector);
81+
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
10582
Table::configureInput($this->getDefinition(), self::$tableHeader, $this->defaultColumns);
10683
PropertyFormatter::configureInput($this->getDefinition());
10784
}
10885

109-
/**
110-
* @return callable|null
111-
*/
112-
protected function getChooseEnvFilter()
113-
{
114-
return SelectorConfig::filterEnvsMaybeActive();
115-
}
116-
11786
/**
11887
* @param InputInterface $input
11988
* @param OutputInterface $output
@@ -232,7 +201,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
232201
),
233202
), $environment);
234203

235-
if (!$this->table->formatIsMachineReadable()) {
204+
/** @var \Platformsh\Cli\Service\Table $table */
205+
$table = $this->getService('table');
206+
if (!$table->formatIsMachineReadable()) {
236207
/** @var PropertyFormatter $formatter */
237208
$formatter = $this->getService('property_formatter');
238209
$this->stdErr->writeln(\sprintf(
@@ -243,9 +214,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
243214
));
244215
}
245216

246-
$this->table->render($rows, self::$tableHeader, $this->defaultColumns);
217+
$table->render($rows, self::$tableHeader, $this->defaultColumns);
247218

248-
if (!$this->table->formatIsMachineReadable()) {
219+
if (!$table->formatIsMachineReadable()) {
249220
$this->explainHighMemoryServices();
250221
$this->stdErr->writeln('');
251222
$this->stdErr->writeln('You can run the <info>cpu</info>, <info>disk</info> and <info>mem</info> commands for more detail.');

src/Command/Metrics/CpuCommand.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Platformsh\Cli\Model\Metrics\MetricKind;
88
use Platformsh\Cli\Model\Metrics\SourceField;
99
use Platformsh\Cli\Model\Metrics\SourceFieldPercentage;
10-
use Platformsh\Cli\Selector\Selector;
1110
use Khill\Duration\Duration;
1211
use Platformsh\Cli\Service\PropertyFormatter;
1312
use Platformsh\Cli\Service\Table;
@@ -33,25 +32,6 @@ class CpuCommand extends MetricsCommandBase
3332
*/
3433
private $defaultColumns = array('timestamp', 'service', 'used', 'limit', 'percent');
3534

36-
/**
37-
* @var PropertyFormatter
38-
*/
39-
private $propertyFormatter;
40-
41-
/**
42-
* @param PropertyFormatter $propertyFormatter
43-
* @param Selector $selector
44-
* @param Table $table
45-
*/
46-
public function __construct(
47-
PropertyFormatter $propertyFormatter,
48-
Selector $selector,
49-
Table $table
50-
) {
51-
$this->propertyFormatter = $propertyFormatter;
52-
parent::__construct($selector, $table);
53-
}
54-
5535
/**
5636
* {@inheritdoc}
5737
*/
@@ -60,10 +40,7 @@ protected function configure()
6040
$this->setName('metrics:cpu')
6141
->setAliases(array('cpu'))
6242
->setDescription('Show CPU usage of an environment');
63-
$this->addMetricsOptions();
64-
$this->selector->addProjectOption($this->getDefinition());
65-
$this->selector->addEnvironmentOption($this->getDefinition());
66-
$this->addCompleter($this->selector);
43+
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
6744
Table::configureInput($this->getDefinition(), self::$tableHeader, $this->defaultColumns);
6845
PropertyFormatter::configureInput($this->getDefinition());
6946
}
@@ -98,7 +75,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9875
),
9976
), $environment);
10077

101-
if (!$this->table->formatIsMachineReadable()) {
78+
/** @var \Platformsh\Cli\Service\Table $table */
79+
$table = $this->getService('table');
80+
if (!$table->formatIsMachineReadable()) {
10281
/** @var PropertyFormatter $formatter */
10382
$formatter = $this->getService('property_formatter');
10483
$this->stdErr->writeln(\sprintf(
@@ -109,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
10988
));
11089
}
11190

112-
$this->table->render($rows, self::$tableHeader, $this->defaultColumns);
91+
$table->render($rows, self::$tableHeader, $this->defaultColumns);
11392

11493
return 0;
11594
}

src/Command/Metrics/DiskUsageCommand.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Platformsh\Cli\Model\Metrics\MetricKind;
88
use Platformsh\Cli\Model\Metrics\SourceField;
99
use Platformsh\Cli\Model\Metrics\SourceFieldPercentage;
10-
use Platformsh\Cli\Selector\Selector;
1110
use Khill\Duration\Duration;
1211
use Platformsh\Cli\Service\PropertyFormatter;
1312
use Platformsh\Cli\Service\Table;
@@ -48,25 +47,6 @@ class DiskUsageCommand extends MetricsCommandBase
4847
*/
4948
private $tmpReportColumns = array('timestamp', 'service', 'tmp_used', 'tmp_limit', 'tmp_percent', 'tmp_ipercent');
5049

51-
/**
52-
* @var PropertyFormatter
53-
*/
54-
private $propertyFormatter;
55-
56-
/**
57-
* @param PropertyFormatter $propertyFormatter
58-
* @param Selector $selector
59-
* @param Table $table
60-
*/
61-
public function __construct(
62-
PropertyFormatter $propertyFormatter,
63-
Selector $selector,
64-
Table $table
65-
) {
66-
$this->propertyFormatter = $propertyFormatter;
67-
parent::__construct($selector, $table);
68-
}
69-
7050
/**
7151
* {@inheritdoc}
7252
*/
@@ -77,10 +57,7 @@ protected function configure()
7757
->setDescription('Show disk usage of an environment')
7858
->addOption('bytes', 'B', InputOption::VALUE_NONE, 'Show sizes in bytes')
7959
->addOption('tmp', null, InputOption::VALUE_NONE, 'Report temporary disk usage (shows columns: ' . implode(', ', $this->tmpReportColumns) . ')');
80-
$this->addMetricsOptions();
81-
$this->selector->addProjectOption($this->getDefinition());
82-
$this->selector->addEnvironmentOption($this->getDefinition());
83-
$this->addCompleter($this->selector);
60+
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
8461
Table::configureInput($this->getDefinition(), self::$tableHeader, $this->defaultColumns);
8562
PropertyFormatter::configureInput($this->getDefinition());
8663
}
@@ -169,7 +146,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
169146
),
170147
), $environment);
171148

172-
if (!$this->table->formatIsMachineReadable()) {
149+
/** @var \Platformsh\Cli\Service\Table $table */
150+
$table = $this->getService('table');
151+
if (!$table->formatIsMachineReadable()) {
173152
/** @var PropertyFormatter $formatter */
174153
$formatter = $this->getService('property_formatter');
175154
$this->stdErr->writeln(\sprintf(
@@ -181,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
181160
));
182161
}
183162

184-
$this->table->render($rows, self::$tableHeader, $this->defaultColumns);
163+
$table->render($rows, self::$tableHeader, $this->defaultColumns);
185164

186165
return 0;
187166
}

src/Command/Metrics/MemCommand.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Platformsh\Cli\Model\Metrics\MetricKind;
88
use Platformsh\Cli\Model\Metrics\SourceField;
99
use Platformsh\Cli\Model\Metrics\SourceFieldPercentage;
10-
use Platformsh\Cli\Selector\Selector;
1110
use Khill\Duration\Duration;
1211
use Platformsh\Cli\Service\PropertyFormatter;
1312
use Platformsh\Cli\Service\Table;
@@ -34,25 +33,6 @@ class MemCommand extends MetricsCommandBase
3433
*/
3534
private $defaultColumns = array('timestamp', 'service', 'used', 'limit', 'percent');
3635

37-
/**
38-
* @var PropertyFormatter
39-
*/
40-
private $propertyFormatter;
41-
42-
/**
43-
* @param PropertyFormatter $propertyFormatter
44-
* @param Selector $selector
45-
* @param Table $table
46-
*/
47-
public function __construct(
48-
PropertyFormatter $propertyFormatter,
49-
Selector $selector,
50-
Table $table
51-
) {
52-
$this->propertyFormatter = $propertyFormatter;
53-
parent::__construct($selector, $table);
54-
}
55-
5636
/**
5737
* {@inheritdoc}
5838
*/
@@ -62,10 +42,7 @@ protected function configure()
6242
->setAliases(array('mem', 'memory'))
6343
->setDescription('Show memory usage of an environment')
6444
->addOption('bytes', 'B', InputOption::VALUE_NONE, 'Show sizes in bytes');
65-
$this->addMetricsOptions();
66-
$this->selector->addProjectOption($this->getDefinition());
67-
$this->selector->addEnvironmentOption($this->getDefinition());
68-
$this->addCompleter($this->selector);
45+
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
6946
Table::configureInput($this->getDefinition(), self::$tableHeader, $this->defaultColumns);
7047
PropertyFormatter::configureInput($this->getDefinition());
7148
}
@@ -103,7 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
10380
),
10481
), $environment);
10582

106-
if (!$this->table->formatIsMachineReadable()) {
83+
/** @var \Platformsh\Cli\Service\Table $table */
84+
$table = $this->getService('table');
85+
if (!$table->formatIsMachineReadable()) {
10786
/** @var PropertyFormatter $formatter */
10887
$formatter = $this->getService('property_formatter');
10988
$this->stdErr->writeln(\sprintf(
@@ -114,9 +93,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
11493
));
11594
}
11695

117-
$this->table->render($rows, self::$tableHeader, $this->defaultColumns);
96+
$table->render($rows, self::$tableHeader, $this->defaultColumns);
11897

119-
if (!$this->table->formatIsMachineReadable()) {
98+
if (!$table->formatIsMachineReadable()) {
12099
$this->explainHighMemoryServices();
121100
}
122101

src/Command/Metrics/MetricsCommandBase.php

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
use Platformsh\Cli\Model\Metrics\Field;
66
use Platformsh\Cli\Model\Metrics\SourceField;
77
use Platformsh\Cli\Model\Metrics\SourceFieldPercentage;
8-
use Platformsh\Cli\Selector\Selector;
9-
use Platformsh\Cli\Selector\SelectorConfig;
108
use Platformsh\Cli\Service\Io;
119
use Platformsh\Cli\Service\PropertyFormatter;
1210
use Platformsh\Cli\Service\Config;
1311
use Platformsh\Cli\Service\Api;
14-
use Platformsh\Cli\Service\Table;
1512
use GuzzleHttp\Exception\BadResponseException;
1613
use Khill\Duration\Duration;
1714
use Platformsh\Cli\Command\CommandBase;
@@ -38,42 +35,6 @@ abstract class MetricsCommandBase extends CommandBase
3835
*/
3936
private $foundHighMemoryServices = false;
4037

41-
/**
42-
* @var Selector
43-
*/
44-
protected $selector;
45-
46-
/**
47-
* @var Table
48-
*/
49-
protected $table;
50-
51-
/**
52-
* @param Selector $selector
53-
* @param Table $table
54-
*/
55-
public function __construct(Selector $selector, Table $table)
56-
{
57-
$this->selector = $selector;
58-
$this->table = $table;
59-
parent::__construct();
60-
}
61-
62-
/**
63-
* @param Api $api
64-
* @param Config $config
65-
* @param Io $io
66-
* @param PropertyFormatter $propertyFormatter
67-
* @return void
68-
*/
69-
public function autowire(Api $api, Config $config, Io $io, PropertyFormatter $propertyFormatter)
70-
{
71-
$this->api = $api;
72-
$this->config = $config;
73-
$this->propertyFormatter = $propertyFormatter;
74-
$this->io = $io;
75-
}
76-
7738
public function isEnabled()
7839
{
7940
if (!$this->config()->getWithDefault('api.metrics', false)) {
@@ -133,24 +94,17 @@ private function getResourcesOverviewUrl(Environment $environment)
13394
*/
13495
protected function processQuery(InputInterface $input, array $metricTypes, array $metricAggs)
13596
{
97+
// Common
98+
$this->chooseEnvFilter = $this->filterEnvsMaybeActive();
99+
$this->validateInput($input, false, true);
100+
$environment = $this->getSelectedEnvironment();
101+
136102
// Common
137103
$timeSpec = $this->validateTimeInput($input);
138104
if (false === $timeSpec) {
139105
throw new \InvalidArgumentException('Invalid time input. Please check the --range, --to, and --interval options.');
140106
}
141107

142-
// Common
143-
$selectorConfig = new SelectorConfig();
144-
$selectorConfig->selectDefaultEnv = true;
145-
$selectorConfig->chooseEnvFilter = $this->getChooseEnvFilter();
146-
$selection = $this->selector->getSelection($input, $selectorConfig);
147-
$environment = $selection->getEnvironment();
148-
149-
// Common
150-
if (!$this->table->formatIsMachineReadable()) {
151-
$this->selector->ensurePrintedSelection($selection);
152-
}
153-
154108
if (!$link = $this->getResourcesOverviewUrl($environment)) {
155109
throw new \InvalidArgumentException('Observability API link not found for the environment.');
156110
}
@@ -263,13 +217,6 @@ private function getServices(InputInterface $input, Environment $environment)
263217
return $selectedServiceNames;
264218
}
265219

266-
/**
267-
* @return callable|null
268-
*/
269-
protected function getChooseEnvFilter()
270-
{
271-
return null;
272-
}
273220

274221
/**
275222
* Validates the interval and range input, and finds defaults.

0 commit comments

Comments
 (0)