@@ 20-54 (lines=35) @@ | ||
17 | use function React\Promise\resolve; |
|
18 | use WyriHaximus\PhuninNode\ConnectionContext; |
|
19 | ||
20 | class Config implements CommandInterface |
|
21 | { |
|
22 | use NodeAwareTrait; |
|
23 | ||
24 | /** |
|
25 | * @param ConnectionContext $context |
|
26 | * @param string $line |
|
27 | * @return PromiseInterface |
|
28 | */ |
|
29 | public function handle(ConnectionContext $context, string $line): PromiseInterface |
|
30 | { |
|
31 | if ($line === '') { |
|
32 | $context->quit(); |
|
33 | return reject(); |
|
34 | } |
|
35 | ||
36 | $plugin = $this->getNode()->getPlugin($line); |
|
37 | ||
38 | if ($plugin === false) { |
|
39 | $context->quit(); |
|
40 | return reject(); |
|
41 | } |
|
42 | ||
43 | return $plugin->getConfiguration()->then( |
|
44 | function ($configuration) { |
|
45 | $lines = []; |
|
46 | foreach ($configuration->getPairs() as $pair) { |
|
47 | $lines[] = $pair->getKey() . ' ' . $pair->getValue(); |
|
48 | } |
|
49 | $lines[] = '.'; |
|
50 | return resolve($lines); |
|
51 | }, |
|
52 | function () { |
|
53 | return resolve([ |
|
54 | '.', |
|
55 | ]); |
|
56 | } |
|
57 | ); |
@@ 20-54 (lines=35) @@ | ||
17 | use function React\Promise\resolve; |
|
18 | use WyriHaximus\PhuninNode\ConnectionContext; |
|
19 | ||
20 | class Fetch implements CommandInterface |
|
21 | { |
|
22 | use NodeAwareTrait; |
|
23 | ||
24 | /** |
|
25 | * @param ConnectionContext $context |
|
26 | * @param string $line |
|
27 | * @return PromiseInterface |
|
28 | */ |
|
29 | public function handle(ConnectionContext $context, string $line): PromiseInterface |
|
30 | { |
|
31 | if ($line === '') { |
|
32 | $context->quit(); |
|
33 | return reject(); |
|
34 | } |
|
35 | ||
36 | $plugin = $this->getNode()->getPlugin($line); |
|
37 | ||
38 | if ($plugin === false) { |
|
39 | $context->quit(); |
|
40 | return reject(); |
|
41 | } |
|
42 | ||
43 | return $plugin->getValues()->then( |
|
44 | function ($values) { |
|
45 | $lines = []; |
|
46 | foreach ($values as $value) { |
|
47 | $lines[] = $value->getKey() . '.value ' . str_replace(',', '.', $value->getValue()); |
|
48 | } |
|
49 | $lines[] = '.'; |
|
50 | return resolve($lines); |
|
51 | }, |
|
52 | function () { |
|
53 | return resolve([ |
|
54 | '.', |
|
55 | ]); |
|
56 | } |
|
57 | ); |