Apply default user-hosted doctrine for all requests

I wrote the following custom walker to use postgres ilike instead of the following:

use Doctrine\ORM\Query\SqlWalker; class IlikeWalker extends SqlWalker { /** * Walks down a SelectClause AST node, thereby generating the desired SQL. * * @param $selectClause * @return string The SQL. */ public function walkLikeExpression($likeExpr) { $sql = parent::walkLikeExpression($likeExpr); $sql = str_replace('LIKE', 'ILIKE', $sql); return $sql; } } 

which can be added to any request via:

  $query->setHint( $query::HINT_CUSTOM_OUTPUT_WALKER ,'\DoctrineExtensions\WalkerBundle\Walker\IlikeWalker' ); 

But how do I start a service or apply a configuration to automatically use this for each request?

+4
source share
2 answers

Doctrine 2.5 has a new defaultQueryHint option in the orm configuration. You can set up a custom walker once for all queries:

 <?php /** @var \Doctrine\ORM\EntityManager $em */ $em->getConfiguration()->setDefaultQueryHint( Query::HINT_CUSTOM_OUTPUT_WALKER, '\DoctrineExtensions\WalkerBundle\Walker\IlikeWalker' ) 

You can use this code in the boot method of your package class:

 class YouBundle extends Bundle { public function boot() { parent::boot(); $this->container ->get('doctrine.orm.entity_manager') ->getConfiguration() ->setDefaultQueryHint( Query::HINT_CUSTOM_OUTPUT_WALKER, '\DoctrineExtensions\WalkerBundle\Walker\IlikeWalker' ); } } 
+7
source

You cannot globally set this hint. Therefore, to solve your problem, I see two ways:

1) register and use your own doctrine function for ILIKE (example here https://github.com/domudall/DoctrineExtensions/blob/master/lib/Dmno/DoctrineExtensions/Comparison/Postgresql/Ilike.php )

2) Use the AOP interceptor ( https://github.com/schmittjoh/JMSAopBundle/blob/master/Resources/doc/index.rst ) to insert $query->setHint.. before each request.

+1
source

All Articles