Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 11 |
DockerCmdTrait | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 11 |
exec | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
parseCmdOutput | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\DockerScale\Retriever\Providers; |
4 | |
5 | use Symfony\Component\Process\Exception\ProcessFailedException; |
6 | use Symfony\Component\Process\Process; |
7 | |
8 | |
9 | trait DockerCmdTrait |
10 | { |
11 | protected function exec(string $cmd, bool $noParsed = false) |
12 | { |
13 | $process = new Process(explode(' ', $cmd)); |
14 | $process->run(); |
15 | |
16 | // executes after the command finishes |
17 | if (!$process->isSuccessful()) { |
18 | throw new ProcessFailedException($process); |
19 | } |
20 | |
21 | return $noParsed ? $process->getOutput() : $this->parseCmdOutput($process->getOutput()); |
22 | } |
23 | |
24 | protected function parseCmdOutput(string $output): array |
25 | { |
26 | $output = trim($output, "\n"); |
27 | $rows = explode("\n", $output); |
28 | return array_map(function($row) { |
29 | $row = trim($row, '"'); |
30 | return explode('|', $row); |
31 | }, $rows); |
32 | } |
33 | |
34 | } |