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

Adding support for Psr-7 #5

Closed
prisis opened this issue Jan 8, 2017 · 6 comments
Closed

Adding support for Psr-7 #5

prisis opened this issue Jan 8, 2017 · 6 comments

Comments

@prisis
Copy link

prisis commented Jan 8, 2017

Not all of use global function/variable's

If you like I can make a pr

@aidantwoods
Copy link
Owner

Would this be so that SecureHeaders communicates with the PSR-7 defined interfaces, or an adapter for it to be the PSR-7 defined interface?

@prisis
Copy link
Author

prisis commented Jan 8, 2017

Like the idea from @franzliedke

Not sure whether this belongs here, but the issue is titled "Usage concerns", so I may as well expand the discussion... The way the library is currently set up, it might be hard to integrate into any modern PHP framework. That's because they typically do not use PHP's global request context methods (such as header and setcookie) directly, but instead operate on various abstractions of HTTP requests and responses.
Most notably, this would probably be PSR-7 requests/responses or the equivalents from Symfony's HttpFoundation component.

So, my first suggestion would be to split the configuration. generation and actual writing of the headers / cookies into separate classes: you'd have a factory that is used for configuring the headers, a class that creates the appropriate HTTP headers and cookies (only the strings) from that configuration, and finally an adapter that actually writes them to either a HTTP response object, or PHP's global functions.
We could then create different adapters for integration with frameworks / other projects: I'd suggest three implementations, for PSR-7, Symfony, as well as the header/setcookie functions

This might seem like overkill, but IMO it would greatly help in a) integratability (I might have made that word up), b) maintainability and c) testability.

And we can use it in all middlewares (PSR-15) ;)

@aidantwoods aidantwoods added this to the Usability milestone Jan 9, 2017
@aidantwoods
Copy link
Owner

Yup I definitely like that idea!

Feel free to make a PR 😄

Function you're looking to for is sendHeaders which makes the only two calls to PHPs header function.

@franzliedke
Copy link
Contributor

If PR #17 gets merged, all you will need to do is provide another implementation of Aidantwoods\SecureHaders\Http\HttpAdapter. :)

@franzliedke
Copy link
Contributor

PR #21 was merged - this will be in v2.0. :)

@franzliedke
Copy link
Contributor

...meaning this issue can be closed. 😎

@prisis prisis closed this as completed Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants