Have you ever wanted to override Symfony2 core Request class?
I am the one of them. Actually what I have would liked to do is overriding isSecure method in Request class bceause of our server configuration was a bit tricky.
I have googled a bit and found useful article on Symfony2 ofiicial document.
It says "you should use setFactoryMethod". HOWEVER "The setFactory() method was added in Symfony 2.4".
I have used Symfony2.3.X because that version has long maintenance term.
I have googled and finally found the solution for Symfony 2.3.X.
You just modify request creation part in web/app.php (and web/app_dev.php).
require_once __DIR__.'/../app/AppKernel.php'; //require_once __DIR__.'/../app/AppCache.php'; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); // You should modify here... // ORIGINAL // $request = Request::createFromGlobals(); // I have added my original request class. class and method name should be what you prepared. $request = MyRequest::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
That's it! Quite easy! However if you know much better solution, please feel free to put comments ;)
Also the next question is coming up for me - "What about overrding Response class?".
Will investigate and hope write a post.
コメント