-
Notifications
You must be signed in to change notification settings - Fork 420
Expand file tree
/
Copy pathSimilarTo.php
More file actions
30 lines (24 loc) · 856 Bytes
/
Copy pathSimilarTo.php
File metadata and controls
30 lines (24 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace DoctrineExtensions\Query\Postgresql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;
class SimilarTo extends FunctionNode
{
public $value = null;
public $regexp = null;
public function parse(Parser $parser): void
{
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->value = $parser->StringPrimary();
$parser->match(TokenType::T_COMMA);
$this->regexp = $parser->StringExpression();
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
public function getSql(SqlWalker $sqlWalker): string
{
return '(' . $this->value->dispatch($sqlWalker) . ' SIMILAR TO ' . $this->regexp->dispatch($sqlWalker) . ')';
}
}