-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Permit HttpFoundation\Request class override #7461
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
Conversation
*/ | ||
public function __construct(HttpKernelInterface $kernel, $cacheDir = null) | ||
public function __construct(HttpKernelInterface $kernel, $cacheDir = null, $requestClass = null) |
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.
Maybe typehint class name instead of just comment ?
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.
You mean __construct(..., $requestClass = 'Symfony\Component\HttpFoundation\Request')
?
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.
More like:
use Symfony\Component\HttpFoundation\Request;
// (...)
public function __construct(..., Request $requestClass = null) {}
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.
But this must be class name (string), not instance :)
By injecting the request class, you're basically creating many many factories. If someone wants to replace some parameters of the create call, then that is not so nice. Why not create a factory and inject that? |
yes, a factory would be the best option. |
@schmittjoh I was thinking about this option while using |
Why do you need to extend the request class? That really should not be necessary, the request should be treated like a value (i.e. data). |
@igorw I totally agree with you... but sometimes, mostly to ease the migration from an old code base to Symfony, this is needed. In fact, I was about to reject the changes we made recently about this, but then I realized that it would help a lot with some of our customers. Moreover, the possibility to override the Request class is documented. So, you should not extend the Request class, but we (unfortunately) should cover this use case. |
} | ||
|
||
protected function createStore() | ||
{ | ||
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache'); | ||
return new Store($this->getKernel()->getContainer()->get('request_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.
You forgot the cache dir ?
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.
@lyrixx wow, good one! thanks :)
@fabpot should I add something to a changelog? If yes, which one? |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpKernel\Request; |
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.
Why putting it in HttpKernel ? It only depends on HttpFoundation
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 put it there because it's only used in HttpKernel, but now that you mention it... I think I should move it.
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.
done
Why use |
@beberlei the idea is to permit to extend the |
@jfsimon i think the config variable is not needed, because overriding the request is only necessary in <1% of all use-cases probably much less and in that case registering your own factory is just a one liner again using the .class% parameter, plus a 10 line factory. That is what the DIC is about and what you try to solve again by building a super generic factory class. |
@beberlei okay, I understand your point. You're right, this is too much. I will remove the |
@jfsimon its just my opinion, it doesn't count for mergeability :-) |
@beberlei I know, but I use to over engineer everything. Simpler is better, isn't it? |
Squashed commits: [Httpernel] added request factory [FrameworkBundle] added request_factory service moved request factory in HttpFoundation component [HttpFoundation] added request factory class check
Rebased & simplified (with a huge delay). |
As overriding the Request class is quite an edge case, I propose something that is less intrusive and still flexible enough: see #8957 |
IMO this patch is the lesser evil than introducing yet another global var on the request, which could lead to strange side-effects. But I believe it can be vastly simplified by removing RequestFactoryInterface and replacing it with a callable that defaults to Just my $0.02. |
@igorw thanks for mentioning theses awful static properties... the solution you propose is the one I used in the first place, then came some convincing comments in favor of a factory. Now I really think this factory is a good point as it may permit to remove the static propoerties from the request. @fabpot what's your mind on this factory + static properties removal thing? |
My idea with the other PR was to reduce the impact of supporting this feature as it is really just an edge case and I'm not comfortable with changing so many things just for that. |
Also, with my hacks, all current bundles creating Requests will be "fixed" automatically. That's not the case with this PR |
As this is really just to fix some edge cases for people moving to Symfony2, I really don't like this PR. So, we can either merge mine or close it as a won't fix. |
…ss (fabpot) This PR was merged into the master branch. Discussion ---------- [HttpFoundation] added a way to override the Request class | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7461, #7453 | License | MIT | Doc PR | symfony/symfony-docs#3021 This is an alternative implementation for #7461. I've also reverted #7381 and #7390 as these changes are not needed anymore. Todo: - [ ] add some tests Commits ------- 464439d [HttpFoundation] added a way to override the Request class
This PR solves #7453. Requests are now created through a
RequestFactoryInterface
.The default factory just call
::create()
method on the request class which can be configured withrequest_class
parameter underframework
section.