initial commit
[namibia] / module / Utility / src / Utility / DoctrineFunction / Soundex.php
1 <?php
2
3 namespace UVd\DoctrineFunction;
4
5 use Doctrine\ORM\Query\Lexer;
6 use Doctrine\ORM\Query\AST\Functions\FunctionNode;
7
8 /**
9  * SOUNDEX
10  *
11  * Allows Doctrine 2.0 Query Language to execute a MySQL SOUNDEX function
12  * You must boostrap this function in your ORM as a DQLFunction.
13  *
14  */
15 class Soundex extends FunctionNode
16 {
17         public $stringExpression = null;
18         public function parse(\Doctrine\ORM\Query\Parser $parser)
19         {
20                 $parser->match(Lexer::T_IDENTIFIER);
21                 $parser->match(Lexer::T_OPEN_PARENTHESIS);
22                 $this->stringExpression = $parser->StringPrimary();
23                 $parser->match(Lexer::T_CLOSE_PARENTHESIS);
24         }
25         public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
26         {
27                 return 'SOUNDEX(' .
28                                 $this->stringExpression->dispatch($sqlWalker) .
29                                 ')';
30         }
31 }