Christopher Vagnetoft 389da4e655 Bugfix Json consumer logic
2026-04-03 01:42:41 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-03 01:42:41 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00
2026-04-02 22:29:35 +02:00

Protocol Base for ReactPHP

Use this library to build protocols. It doesn't do any single protocol to any greater extent, but it provides callbacks and scaffolding for you to build and stream most protocol data.

About the protocols

This library is intended to be generic, so only protocols that have no external dependencies will be included.

Using

Protocols

// Basic line-oriented protocol, think shell or SMTP
$proto = new LineProtocol($stream, [
    'lineSeparator' => "\n",
    'fieldSeparator' => " ",
    'fieldQuote' => '"',
]);

// encode your frames and send it however you desire
$data = $proto->packFrame([ "mv", "foo.txt", "bar.txt" ]);
// → mv foo.txt bar.txt\n

// Or use JSON if you so desire
$proto = new JsonProtocol($stream, [
    'frameSeparator' => "\0",
]);
$data = $proto->packFrame([ 'foo' => 'bar' ]);
// → {"foo":"bar"}\0

Unpacking works as expected:

$proto = new LineProtocol($stream, [
    'lineSeparator' => "\n",
    'fieldSeparator' => " ",
    'fieldQuote' => '"',
]);

// encode your frames and send it however you desire
$cmdline = $proto->unpackFrame("mv foo.txt bar.txt\n" ]);
// → [ "mv", "foo.txt", "bar.txt" ]

Protocols with ProtocolStream

ProtocolStream combines a ProtocolInterface and a DuplexStreamInterface into one package. It will emit an message event when a new frame has been decoded, an error event if something goes wrong, and an overflow event if the buffer overflows a configured max size.

$stream = new ProtocolStream($proto, $someduplexstream);
$stream->on("message", function (array $message) {
    // ...
});
$stream->send([ 'data' => 'here' ]);
Description
No description provided
Readme GPL-2.0 58 KiB
Languages
PHP 100%