Thanks for bringing this up, Martijn. I agree that bit is rather
awkward and should be clarified and tested better.

I think the docblock was intended to read:

> The resource MUST be readable and may be writable.

However, even if that was the case, how would it be enforced? I don't
know of a way to check if a resource is readable.

This may require an errata to PSR-17.
--
Woody Gilk
https://shadowhand.me
On Sun, Sep 2, 2018 at 2:04 PM Martijn van der Ven
<martijn.perso...@gmail.com> wrote:
>
> 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, 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 php-fig+unsubscr...@googlegroups.com.
> To post to this group, send email to php-fig@googlegroups.com.
> 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.

-- 
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 php-fig+unsubscr...@googlegroups.com.
To post to this group, send email to php-fig@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/CAGOJM6KsdC6uaWzekOOY7J20B3Cdy93Pk%3Dj_ZGTgxUkozvh2SQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to