Долгими мучениями всё-таки сделал:
<?php
namespace AppBundle\DQL;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
/**
* MBRContainsFunction ::= "MBRContains" "(" StringPrimary ", " StringExpression ", " StringExpression ")"
*/
class MBRContainsFunction extends FunctionNode
{
public $polygonExpression = null;
public $pointCordOne = null;
public $pointCordTwo = null;
public function getSql(SqlWalker $sqlWalker)
{
$returnString = 'MBRContains(GeomFromText(' . $this->polygonExpression->dispatch($sqlWalker) . '), '.
'Point(' . $this->pointCordOne->dispatch($sqlWalker) .', '. $this->pointCordTwo->dispatch($sqlWalker) .'))';
return $returnString;
}
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->polygonExpression = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->pointCordOne = $parser->StringExpression();
$parser->match(Lexer::T_COMMA);
$this->pointCordTwo = $parser->StringExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
Использование:
$coords = '123,123 200,200 123,200 123,123';
$this->createQueryBuilder('offer')
->andWhere('MBRContains(:coords, offer.latitude, offer.longitude) = TRUE')
->setParameter('coords', 'Polygon(('. $coords .'))');