Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Decouple Visitor and Stream for Renderers #143

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

nibra
Copy link
Member

@nibra nibra commented Apr 24, 2017

Covers PR#142.

Because the PSR-7 HTTP middleware requires the response body to be a message stream, the renderers were built to not only implement the visitor pattern, but also the PSR-7 message stream interface.

For layouts and templates, streams are not easy to handle, especially, when things need to be inserted in certain positions. Whenever the buffer content changes, the cursor position needs to be re-calculated. Even for appending it is needed to move the pointer to the end of the buffer first.

That is way too complicated and prune to errors.

This PR separates the stream from the renderers. A renderer manages its own string buffer, if needed,
After rendering, the buffer is wrapped into a PSR-7 compatible stream and attached as body to the response, as that is the only place, where the output has to be a stream.

ContentTypeVisitorTrait is introduced with this PR to simplify the handling of visitor methods, especially in case they are very similar. Additionally, renderers using that trait are much more robust against changes in the ContentTypeVisitorInterface, as they automatically provide a fallback for new content types.

@nibra nibra requested a review from laoneo April 24, 2017 22:07
@nibra nibra added this to the CDH milestone Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant