match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->latitude1 = $parser->ArithmeticPrimary(); $parser->match(Lexer::T_COMMA); $this->longitude1 = $parser->ArithmeticPrimary(); $parser->match(Lexer::T_COMMA); $this->latitude2 = $parser->ArithmeticPrimary(); $parser->match(Lexer::T_COMMA); $this->longitude2 = $parser->ArithmeticPrimary(); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } /** * Get SQL. * * @throws ASTException */ public function getSql(SqlWalker $sqlWalker): string { $R = 6371; // Rayon terrestre, en km $lat2 = $this->latitude2->dispatch($sqlWalker); $lat1 = $this->latitude1->dispatch($sqlWalker); // Call two additional dispatch so doctrine complete the parameters stack (careful: the order is important) $this->latitude1->dispatch($sqlWalker); $this->latitude2->dispatch($sqlWalker); $lon1 = $this->longitude1->dispatch($sqlWalker); $lon2 = $this->longitude2->dispatch($sqlWalker); // Latitudes et longitudes en radians $rLat1 = "($lat1 * PI() / 180)"; $rLon1 = "($lon1 * PI() / 180)"; $rLat2 = "($lat2 * PI() / 180)"; $rLon2 = "($lon2 * PI() / 180)"; return "2 * $R * ASIN(SQRT(POW(SIN(($rLat2 - $rLat1) / 2), 2) + COS($rLat1) * COS($rLat2) * POW(SIN(($rLon2 - $rLon1) / 2), 2)))"; } }