Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Conversation

@weierophinney
Copy link
Member

In the getting started tutorial, this sample code is shown:

$app->get('/', function ($request, $response, $next) {
    $response->write('Hello, world!');
    return $response;
});

I don't think that's valid as the Psr\Http\Message\ResponseInterface has no write() method.
It should be changed to $response->getBody()->write('Hello, world!');

(If the PSR-7 http implementations are Slim's request and response, this can work, as they added this non-PSR-7's method into their Response implementation, but it doesn't seem correct to me as the router's callback expects a response of the type Psr\Http\Message\ResponseInterface, thus we are violating the contract)

@geerteltink
Copy link
Member

The actual response is Zend\Stratigility\Http\Response which implements the Psr\Http\Message\ResponseInterface and the Zend\Stratigility\Http\ResponseInterface. The last one implements the write() method.

Looking at the Slim docs and code, I think Slim works the same. Only the actual response is a Slim/Http/Response.

I'm guessing the reason to choose the Psr\Http\Message\ResponseInterface is to keep it compatible with other middleware. If you force the Zend\Stratigility\Http\ResponseInterface you would loose that. The write() method is a nice extra with some extra benefits since it check if it is allowed to write.

I guess you could change the docs so the contract is not violated and mention you can use Zend\Stratigility\Http\ResponseInterface methods as well.

@mathieuprog
Copy link
Author

I was supposing that Zend Diactoros' interfaces were used, for which the response interface does not include that extra write() method. I didn't know Zend Stratigility's interfaces are actually being used.

In any case that should be updated as it breaks the contract and is a bad practice, also it breaks the whole idea to have framework-agnostic middlewares through PSR-7's http abstraction.

@weierophinney
Copy link
Member

@mdecaffmeyer is correct; the examples should be showing PSR-7 usage, not Stratigility-specific stuff. We can accommodate any PSR-7-based middleware.

Examples should demonstrate usage of PSR-7 interfaces only,
not-Stratigility-specific features.
@weierophinney weierophinney self-assigned this Dec 17, 2015
@weierophinney weierophinney merged commit a063fbd into zendframework:master Dec 17, 2015
weierophinney added a commit that referenced this pull request Dec 17, 2015
weierophinney added a commit that referenced this pull request Dec 17, 2015
@weierophinney weierophinney deleted the hotfix/232 branch December 17, 2015 21:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants