diff options
Diffstat (limited to 'vendor/gipfl/icinga-cli-daemon/src/IcingaCliRpc.php')
-rw-r--r-- | vendor/gipfl/icinga-cli-daemon/src/IcingaCliRpc.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/gipfl/icinga-cli-daemon/src/IcingaCliRpc.php b/vendor/gipfl/icinga-cli-daemon/src/IcingaCliRpc.php new file mode 100644 index 0000000..473d4ed --- /dev/null +++ b/vendor/gipfl/icinga-cli-daemon/src/IcingaCliRpc.php @@ -0,0 +1,45 @@ +<?php + +namespace gipfl\IcingaCliDaemon; + +use Exception; +use gipfl\Protocol\JsonRpc\Connection; +use gipfl\Protocol\NetString\StreamWrapper; +use React\ChildProcess\Process; + +class IcingaCliRpc extends IcingaCli +{ + /** @var IcingaCliRunner */ + protected $runner; + + /** @var Connection|null */ + protected $rpc; + + protected $arguments = []; + + protected function init() + { + $this->on('start', function (Process $process) { + $netString = new StreamWrapper( + $process->stdout, + $process->stdin + ); + $netString->on('error', function (Exception $e) { + $this->emit('error', [$e]); + }); + $this->rpc()->handle($netString); + }); + } + + /** + * @return Connection + */ + public function rpc() + { + if ($this->rpc === null) { + $this->rpc = new Connection(); + } + + return $this->rpc; + } +} |