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

Reduce static coupling to Controller::has_curr() and Controller::curr() #4484

Open
sminnee opened this issue Aug 4, 2015 · 3 comments
Open

Comments

@sminnee
Copy link
Member

sminnee commented Aug 4, 2015

A lot of support code (e.g. the error display handler) winds up hooking into Controller::has_curr() and Controller::curr(). This is awkward coupling, and it will make it harder to use SilverStripe code with other controller implementations.

Initially, I've posted this issue as an anchor point so that I can refer to it in TODO comments in code.

@tractorcow
Copy link
Contributor

A lot of the time this is necessary because the current request is only available from the current controller. Maybe we should have SS_HTTPRequest::curr() instead?

@sminnee
Copy link
Member Author

sminnee commented Aug 5, 2015

My reason for raising this was to suggest to that we reduce the amount of static coupling. SS_HTTPRequest::curr() would be of limited value.

@sminnee sminnee changed the title Reduce coupling to Controller::has_curr() and Controller::curr() Reduce static coupling to Controller::has_curr() and Controller::curr() Aug 5, 2015
@sminnee
Copy link
Member Author

sminnee commented Aug 5, 2015

For example, we might want to inject something into HTTPOutputHandler that can receive the responses, I guess that it might be better to have some kind of output destination for errors? If nothing else, it would make it easier to test.

Assuming that we move towards PSR-7, which uses immuatable response object, then the injected property might be a writer with an interface like this

interface HttpWriter {
    function write(Psr\Http\Message\ResponseInterface $response);
}

HTTPOutputHandler can then output like this, rather than calling response->output(), and probably don't need to get the Controller response at all...

$this->httpWriter->write($errorResponse);

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

4 participants