Closed martin-rueegg closed 4 years ago
Before diving into your PR, how similar is it to https://github.com/reactphp/socket ?
Thanks, @WyriHaximus, for your comment.
Actually, it seems to be what UnixServer is doing!
Gosh, I was looking into reactphp/socket last night but could not see it! Now it's there ... Hahaha.
Ok, forget this PR then.
@martin-rueegg no problem, and thank you for the time putting this together. Quickly skimmed over it and I'm impressed by what I see š .
hey @WyriHaximus,
you're welcome and thanks for the compliments.
I have one question, which I take the opportunity of this PR to ask:
Why are the classes made final
? What is the rationale behind it to not allow developers to extend your classes?
Thanks, Martin.
@martin-rueegg TL;DR to encourage composition over inheritance: https://github.com/reactphp/stream/commit/49ecaa434e6be851c3bdef225358f53095956d97
I see. Thanks for your quick responses. Awesome!
Hi there
I have not seen any contribution guidelines so I hope this is an acceptable way for a change request. Please kindly let me know if an other way (e.g. creating an issue first) is preferred.
I needed to implement a stream server. Unfortunately I have not found a way to achieve this with your existing classes. Eventually, I wanted to extend your
ReadableResourceStream
, but given that the properties are private and it is markedfinal
, I decided to create a new base class (AbstractReadableResourceStreamBase
) instead and then extend the currentReadableResourceStream
and the newStreamServerStream
from it. This has the advantage, that the methodpipe()
is not included in the latter, as it would not be supported anyway (unless all connections would be piped to a new endpoint. But that would require quite a different implementation). As a consequence, I had also done the same move for the appropriate interfaces.So, basically I did the following:
ReadableStreamInterface
->ReadableStreamBaseInterface
ReadableStreamInterface
extendingReadableStreamBaseInterface
pipe()
fromReadableStreamInterface
->ReadableStreamBaseInterface
ReadableStreamInterface
extendingReadableStreamBaseInterface
ReadableResourceStream
->AbstractReadableResourceStreamBase
AbstractReadableResourceStreamBase
abstract
, rather thanfinal
ReadableStreamBaseInterface
, rather thanReadableStreamInterface
ReadableResourceStream
AbstractReadableResourceStreamBase
ReadableStreamInterface
pipe()
fromAbstractReadableResourceStreamBase
->ReadableResourceStream
StreamServerStream
AbstractReadableResourceStreamBase
StreamServerInterface
__construct()
to create newstream_socket_server()
from string argumenthandleData()
te get the new client stream and emit eventnew
If you agree, that this would be a useful extension, the following needs to be done (at least):
StreamServerStream::__construct()
emit
, e.gDuplexResourceStream::class
which would then be the type of the first argument to the listeners.Looking forward to your comments and suggestions.
Thank you for your time, Martin.