Skip to content

Commit 54a5b37

Browse files
fix: add support for Lexer v1 (allowed by ORM < v2.15)
1 parent 92be1de commit 54a5b37

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,25 @@ permissions:
1111

1212
jobs:
1313
tests:
14-
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }}"
14+
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }} + Doctrine Lexer ${{ matrix.doctrine-lexer }}"
1515
runs-on: ubuntu-latest
1616

1717
strategy:
1818
fail-fast: false
1919
matrix:
2020
php: ['8.1', '8.2', '8.3', '8.4']
21-
doctrine-orm: ['2.14', '3.0', 'latest']
21+
doctrine-lexer: ['2.1', '3.0', 'latest']
22+
doctrine-orm: ['2.14', '2.18', '3.0', 'latest']
2223
include:
24+
- doctrine-orm: '2.14'
25+
doctrine-lexer: '1.2'
2326
- php: '8.4'
2427
calculate-code-coverage: true
28+
exclude:
29+
- doctrine-orm: '2.14'
30+
doctrine-lexer: '3.0'
31+
- doctrine-orm: '3.0'
32+
doctrine-lexer: '2.1'
2533

2634
steps:
2735
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -46,10 +54,24 @@ jobs:
4654
restore-keys: |
4755
${{ runner.os }}-php-
4856
49-
- name: Install composer dependencies
57+
- name: Install Doctrine Lexer dependency
58+
run: |
59+
if [ "${{ matrix.doctrine-lexer }}" == "1.2" ]; then
60+
composer require doctrine/lexer "~1.2" --dev --prefer-dist --no-interaction --no-progress
61+
elif [ "${{ matrix.doctrine-lexer }}" == "2.1" ]; then
62+
composer require doctrine/lexer "~2.1" --dev --prefer-dist --no-interaction --no-progress
63+
elif [ "${{ matrix.doctrine-lexer }}" == "3.0" ]; then
64+
composer require doctrine/lexer "~3.0" --dev --prefer-dist --no-interaction --no-progress
65+
else
66+
composer update --prefer-dist --no-interaction --no-progress
67+
fi
68+
69+
- name: Install Doctrine ORM dependency
5070
run: |
5171
if [ "${{ matrix.doctrine-orm }}" == "2.14" ]; then
5272
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress
73+
elif [ "${{ matrix.doctrine-orm }}" == "2.18" ]; then
74+
composer require doctrine/orm "~2.18" --prefer-dist --no-interaction --no-progress
5375
elif [ "${{ matrix.doctrine-orm }}" == "3.0" ]; then
5476
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress
5577
else

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Doctrine\ORM\Query\TokenType;
1212
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
1313
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\ParserException;
14+
use MartinGeorgiev\Utils\DoctrineLexer;
1415
use MartinGeorgiev\Utils\DoctrineOrm;
1516

1617
/**
@@ -30,24 +31,24 @@ protected function feedParserWithNodes(Parser $parser): void
3031
try {
3132
// @phpstan-ignore-next-line
3233
$this->nodes[] = $parser->{$this->commonNodeMapping}();
33-
if ($lexer->lookahead?->type === null) {
34+
$lookaheadType = DoctrineLexer::getLookaheadType($lexer);
35+
if ($lookaheadType === null) {
3436
throw ParserException::missingLookaheadType();
3537
}
3638
} catch (\Throwable $throwable) {
3739
throw ParserException::withThrowable($throwable);
3840
}
3941

40-
$aheadType = $lexer->lookahead->type;
4142
$shouldUseLexer = DoctrineOrm::isPre219();
4243

43-
while (($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $aheadType) {
44-
if (($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA) === $aheadType) {
44+
while (($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $lookaheadType) {
45+
if (($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA) === $lookaheadType) {
4546
$parser->match($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA);
4647
// @phpstan-ignore-next-line
4748
$this->nodes[] = $parser->{$this->commonNodeMapping}();
4849
}
4950

50-
$aheadType = $lexer->lookahead->type;
51+
$lookaheadType = DoctrineLexer::getLookaheadType($lexer);
5152
}
5253

5354
$this->validateArguments($this->nodes);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MartinGeorgiev\Utils;
6+
7+
use Doctrine\ORM\Query\Lexer;
8+
9+
/**
10+
* @internal
11+
*/
12+
final class DoctrineLexer
13+
{
14+
public static function isPre200(Lexer $lexer): bool
15+
{
16+
// @phpstan-ignore-next-line
17+
return \is_array($lexer->lookahead);
18+
}
19+
20+
/**
21+
* @return mixed|null
22+
*/
23+
public static function getLookaheadType(Lexer $lexer)
24+
{
25+
if (self::isPre200($lexer)) {
26+
// @phpstan-ignore-next-line
27+
return $lexer->lookahead['type'];
28+
}
29+
30+
// @phpstan-ignore-next-line
31+
return $lexer->lookahead?->type;
32+
}
33+
}

0 commit comments

Comments
 (0)