Commit
The Response is not available in the DIC anymore. When you need to create a response, create an instance of Symfony\Component\HttpFoundation\Response instead. As a side effect, the Controller::createResponse() and Controller::redirect() methods have been removed and can easily be replaced as follows: return $this->createResponse('content', 200, array('foo' => 'bar')); return new Response('content', 200, array('foo' => 'bar')); return $this->redirect($url); return Response::createRedirect($url);
- Loading branch information
There are no files selected for viewing
5 comments
on commit d94acd8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is problematic for me. I don't think we should be encouraging and making available static methods for people to be using throughout their code. It breaks testability. I think the best practice and offered solution in Symfony should be a ResponseFactory instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Response::createRedirect
method has been dropped in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now. Cool. Looks good! :) Now we just need in the docs to not promote direct use of new Response and that a proper testable solution would be a factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By ResponseFactory you mean having a service calling new Response()
(which is basically what has been removed here) or the eager response supported by johannes and lsmith ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it is not basically what has been removed. The DI container was creating the Response objects so it was essentially acting as the factory. Fabien didn't want the DI container to be the factory for responses. If you directly create new Responses or create them via static methods you have no chance to mock them. That is why a ResponseFactory would be ideal, so that you can mock it and tell phpunit to return a mock response when you call createResponse()
That makes sense. I will create a RedirectResponse class.