slimphp / PHP-View

A Simple PHP Renderer for Slim 3 & 4 (or any other PSR-7 project)
MIT License
264 stars 60 forks source link

QUESTION #25

Closed pine3ree closed 8 years ago

pine3ree commented 8 years ago

Hello,

I was wondering why the render method has a ResponseInterfaceparameter. Wouldn't it be better to write to the body inside the route-matching middleware:

$response->getBody()->write(
    $this->view->render('someTemplate.phtml', $someData)
);

and have the PhpRenderer just do 1 job: pass data into a template and return the resulting string? For instance, what if i just need to render a template for an html email? Doesn't this also violate the SRP? In my opinion a view renderer shouldn't have the responsibility of filling a response.

thanks and kind regards maks

geggleto commented 8 years ago

Largely the decision was to try and mirror the Twig Package.

If we wanted to get really technical the view should be provided a PSR Stream interface, but it would be a huge BC break.

Separately we are looking at providing a unified view interface, but it will likely take a bit to work out all the details for it,

We do provide a way to render a template to a string.

https://github.com/slimphp/PHP-View/blob/master/src/PhpRenderer.php#L148

I hope this answers your question

pine3ree commented 8 years ago

@geggleto Thank You for the explaination on the design choice. kind regards