slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.97k stars 1.95k forks source link

V4 proposal: Returning Responses and rendering templates #1931

Closed akrabat closed 7 years ago

akrabat commented 8 years ago

There's no real need for a $response parameter in the route callable as it shouldn't be modified on the way in anyway.

As such, the user should create a new Response object in the route callable to return. Fortunately Slim's Response object doesn't have any required parameters, so this is easy:

return new \Slim\Http\Response();

We could also handle specialised Responses with new classes rather than more with methods on Response:

For HTML output, it's convenient to use a template engine such a Twig, Plates or a separate PHP file. For these cases, I suggest we use "View" classes with a render() method that returns a Response object:

JoeBengalen commented 8 years ago

The first part sounds alot like zend-diactoros: https://github.com/zendframework/zend-diactoros/tree/master/src/Response

jirkahronik commented 8 years ago

Can you please expand on why the response object shouldn't be modified on its way through middleware stack? I actually find it a very interesting feature - e.g. setting default headers to the response that can be overridden in the route callable.

geggleto commented 8 years ago

@jirkahronik That is the design decision of the PHP-FIG.

akrabat commented 7 years ago

This becomes moot with the proposed PSR for HTTP Middleware.