I have been spending some time this weekend with the HTTP Interop unit tests for HTTP Factories (PSR-17) and ended up puzzling about createStreamFromResource’s strict (RFC 2119 “MUST”) requirement on the output Stream being readable:
/** * Create a new stream from an existing resource. * * The stream MUST be readable and may be writable. * * @param resource $resource The PHP resource to use as the basis for the stream. */ public function createStreamFromResource($resource): StreamInterface; For argument’s sake, say we have the following code: $resource = fopen(tempnam(sys_get_temp_dir(), 'psr17'), 'w'); fwrite($resource, 'Foobar'); $stream = $factory->createFromResource($resource); What functionality should exist on the returned Stream? The interface is telling me it must be readable, but we don’t have a clean way to read from the existing resource at all and can probably never access the “Foobar” string that already exists in the file. I would have expected the interface to define a \RuntimeException in case the provided $resource is unreadable. Like how createStreamFromFile defines it for files it couldn’t open. Or to just not have put this requirement on the output at all, createStreamFromFile allows write-only streams to be created. I couldn’t find any sort of discussion about this in the meta document or on the (now deprecated) proposal GitHub repo <https://github.com/http-interop/http-factory>, so maybe someone here can tell me why this method is the way it is. (Sadly I didn’t spot this back when I was working with it during its proposal stage.) Regards, Martijn van der Ven https://vanderven.se/martijn/ -- You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/1ad6929e-ab43-4a38-8b29-cf5bd2799062%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
