for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;
/**
* @author Martin Georgiev <[email protected]>
*/
abstract class BaseVariadicFunction extends BaseFunction
{
protected string $commonNodeMapping = 'StringPrimary';
public function feedParserWithNodes(Parser $parser): void
$lexer = $parser->getLexer();
$this->nodes[] = $parser->{$this->commonNodeMapping}();
if (!$lexer->lookahead?->type) {
throw new \RuntimeException('The parser\'s "lookahead" property is not populated with a type');
}
$aheadType = $lexer->lookahead->type;
$ormV2 = !class_exists(TokenType::class);
while (($ormV2 ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $aheadType) {
Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS
if (($ormV2 ? Lexer::T_COMMA : TokenType::T_COMMA) === $aheadType) {
Doctrine\ORM\Query\Lexer::T_COMMA
$parser->match($ormV2 ? Lexer::T_COMMA : TokenType::T_COMMA);
public function getSql(SqlWalker $sqlWalker): string
$dispatched = [];
foreach ($this->nodes as $node) {
$dispatched[] = $node instanceof Node ? $node->dispatch($sqlWalker) : 'null';
return \sprintf($this->functionPrototype, \implode(', ', $dispatched));