Is there a way to access the symfony2 container wi

2020-06-27 07:12发布

is there any possibility to get the service-container of symfony2 within an SQLFilter or can i maybe directly use a service as SQLFilter?

I know that this isn't a "clean" way, but i have to perform several checks directly before the final submit of the query gets fired (as i have to append conditions to the WHERE-statement, i can't use lifecycle-events at this point).

1条回答
可以哭但决不认输i
2楼-- · 2020-06-27 07:54

it's not clean but you could try this:

<?php

class MyBundle extends Bundle 
{
public function boot()
{
    $em = $this->container->get('doctrine.orm.default_entity_manager');
    $conf = $em->getConfiguration();
    $conf->addFilter(
        'test',
        'Doctrine\Filter\TestFilter'
    );

    $em->getFilters()->enable('test')->setContainer($this->container);
}
}
查看更多
登录 后发表回答