I think this problem can be traced back to PSR-7, which doesn't specify 
anything about constructors - e.g. doesn't specify anything about the 
initial state of the models for which it defines abstractions.

You could argue PSR-7 shouldn't deal with creation and should only define 
the behavior of the methods it defines.

I suppose I'd tend to agree - we have PSR-17 that defines details about 
creation.

The conundrum, however, is that PSR-7 existed long before PSR-17, and still 
exists as an independent spec - which, if it doesn't deal with creation, 
arguably defines something that isn't really meaningful or complete in 
itself.

Anyhow, if we can let go of the past (and ignore reality for a bit) and 
pretend that PSR-7 is just sort of a sub-component of a more complete 
PSR-17 standard, I guess I'd say we need to further amend PSR-17 to address 
this.

Not sure if you saw my current PR here:

https://github.com/php-fig/fig-standards/compare/master...mindplay-dk:stream-pointer-state

I guess I'd propose the following addition to each of Section 2.1, 2.2 and 
2.3:

"Implementations of this interface MUST initialize the body stream with an 
empty temp-stream in read/write mode, e.g. fopen('php://temp', 'rw+')"

And then of course expanding on the errata section with a short rationale.

Thoughts?

On Monday, January 7, 2019 at 10:32:04 AM UTC+1, Oscar Otero wrote:
>
> Hi.
> In this example:
>
> $response = $responseFactory->createResponse(200);
>
> $body = $response->getBody();
> $body2 = $streamFactory->createStream();
>
> I've always assumed that $body and $body2 were empty writable streams, so 
> it was safe to write in them. But PSR-17 says nothing about how the streams 
> must be created in new http messages (request, serverRequest and responses).
> This problem appeared here 
> https://github.com/middlewares/error-handler/pull/5/files#r227117082 and 
> forces to always require a streamFactory along with a responseFactory any 
> time that you have to create a response in a middleware.
> I think this makes the responseFactory less useful and reliable, forcing 
> to require more dependencies just in case.
>
> So I propose to include in the spec a text indicating that the stream 
> created in the responseFactory, requestFactory and serverRequestFactory 
> should be the same than if they were created with 
> streamFactory->createStream()
>
> What do you think?
>
> Oscar Otero.
>

-- 
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/8de55cee-f444-4163-a0d1-ad54d22c5b05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to