I'm following How to Override any Part of a Bundle page on Symfony 2 website. This is interesting:
You can set the parameter holding the service's class name to your own class by setting it in app/config/config.yml. This of course is only possible if the class name is defined as a parameter in the service config of the bundle containing the service.
So i looked at /vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config and i found that session.xml is defining %session.class% parameter, so it should be easy to extend Symfony Session class with something like:
namespace Acme\HelloBundle\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\Session;
class ExtendedSession extends Session
{
public function setSuccessFlashText($text, array params = array())
{
parent::setFlash('success', $this->getTranslator()->trans($text, $params);
}
}
I din't tested this yet. But how can i do the same with request special service? I'd like to adding some convenient shortcuts in order to make my code easier to read.
I found this in services.xml file:
<!--
If you want to change the Request class, modify the code in
your front controller (app.php) so that it passes an instance of
YourRequestClass to the Kernel.
This service definition only defines the scope of the request.
It is used to check references scope.
-->
<service id="request" scope="request" synthetic="true" />
Here is my app.php. How i'm supposed to pass an instance of my custom request class?
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$kernel->handle(Request::createFromGlobals())->send();