| @@ 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 | public function handle(ConnectionContext $context, string $line): PromiseInterface |
|
| 25 | { |
|
| 26 | if ($line === '') { |
|
| 27 | $context->quit(); |
|
| 28 | return reject(); |
|
| 29 | } |
|
| 30 | ||
| 31 | $plugin = $this->getNode()->getPlugin($line); |
|
| 32 | ||
| 33 | if ($plugin === false) { |
|
| 34 | $context->quit(); |
|
| 35 | return reject(); |
|
| 36 | } |
|
| 37 | ||
| 38 | return $plugin->getConfiguration()->then( |
|
| 39 | function ($configuration) { |
|
| 40 | $lines = []; |
|
| 41 | foreach ($configuration->getPairs() as $pair) { |
|
| 42 | $lines[] = $pair->getKey() . ' ' . $pair->getValue(); |
|
| 43 | } |
|
| 44 | $lines[] = '.'; |
|
| 45 | return resolve($lines); |
|
| 46 | }, |
|
| 47 | function () { |
|
| 48 | return resolve([ |
|
| 49 | '.', |
|
| 50 | ]); |
|
| 51 | } |
|
| 52 | ); |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||
| @@ 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 | public function handle(ConnectionContext $context, string $line): PromiseInterface |
|
| 25 | { |
|
| 26 | if ($line === '') { |
|
| 27 | $context->quit(); |
|
| 28 | return reject(); |
|
| 29 | } |
|
| 30 | ||
| 31 | $plugin = $this->getNode()->getPlugin($line); |
|
| 32 | ||
| 33 | if ($plugin === false) { |
|
| 34 | $context->quit(); |
|
| 35 | return reject(); |
|
| 36 | } |
|
| 37 | ||
| 38 | return $plugin->getValues()->then( |
|
| 39 | function ($values) { |
|
| 40 | $lines = []; |
|
| 41 | foreach ($values as $value) { |
|
| 42 | $lines[] = $value->getKey() . '.value ' . str_replace(',', '.', $value->getValue()); |
|
| 43 | } |
|
| 44 | $lines[] = '.'; |
|
| 45 | return resolve($lines); |
|
| 46 | }, |
|
| 47 | function () { |
|
| 48 | return resolve([ |
|
| 49 | '.', |
|
| 50 | ]); |
|
| 51 | } |
|
| 52 | ); |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||