Improved quality of docblock comments

This commit is contained in:
2018-04-15 22:08:19 +02:00
parent 20b6f1d42c
commit 31634c5054
9 changed files with 132 additions and 7 deletions

View File

@ -2,11 +2,19 @@
namespace NoccyLabs\Ipc\Interop\Channel;
/**
* Channel based on streams
*
*/
class StreamChannel implements ChannelInterface
{
protected $stream;
/**
* Constructor
*
* @param resource|string $stream
*/
public function __construct($stream)
{
if (!is_resource($stream)) {
@ -20,15 +28,24 @@ class StreamChannel implements ChannelInterface
}
$this->stream = $stream;
$this->isOpen();
}
/**
* {@inheritDoc}
*
* @param mixed $data
* @return void
*/
public function send($data)
{
fwrite($this->stream, json_encode($data)."\0");
}
/**
* {@inheritDoc}
*
* @return mixed
*/
public function receive()
{
$buf = fread($this->stream, 8192);
@ -36,11 +53,21 @@ class StreamChannel implements ChannelInterface
return json_decode(rtrim($buf, "\0"));
}
/**
* {@inheritDoc}
*
* @return boolean
*/
public function isOpen(): bool
{
return is_resource($this->stream);
}
/**
* Create a pair of connected StreamChannel instances
*
* @return StreamChannel[]
*/
public static function createPair()
{
$fd = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);