I have a Doctrine filter in Symfony2 project. I am trying to set filter's parameter to some value (taken from session) on every request. The problem is that filter object is created after Symfony's onKernelRequest event, so I can't set it from there. If I try to set it in Doctrine's postConnect event circular dependency is detected:
ServiceCircularReferenceException: Circular reference detected for service "doctrine.orm.private_entity_manager", path: "routing.loader -> assetic.asset_manager -> twig -> translator.default -> doctrine.orm.private_entity_manager -> doctrine.dbal.private_connection -> year_visibility.parameter_setter".
The question is, where (or rather how) should I set filter's parameter?
As seen here: https://stackoverflow.com/a/14650403/244058 ,
you can have an instance of your Filter class at kernel boot. So, your instance would be available very early.
After that, just add a kernel.event_listener that listens on
kernel.request
and set a filter parameter (something like this):You can try to define filters manually and pass required parameters at the same time.
And in the filter manager class: