Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TokenType class #11228

Merged
merged 8 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Upgrade to 2.19

## Deprecate `Doctrine\ORM\Query\Lexer::T_*` constants

Use `Doctrine\ORM\Query\TokenType::T_*` instead.

# Upgrade to 2.17

## Deprecate annotations classes for named queries
Expand Down
20 changes: 10 additions & 10 deletions docs/en/cookbook/dql-user-defined-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ discuss it step by step:

public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER); // (2)
$parser->match(Lexer::T_OPEN_PARENTHESIS); // (3)
$parser->match(TokenType::T_IDENTIFIER); // (2)
$parser->match(TokenType::T_OPEN_PARENTHESIS); // (3)
$this->firstDateExpression = $parser->ArithmeticPrimary(); // (4)
$parser->match(Lexer::T_COMMA); // (5)
$parser->match(TokenType::T_COMMA); // (5)
$this->secondDateExpression = $parser->ArithmeticPrimary(); // (6)
$parser->match(Lexer::T_CLOSE_PARENTHESIS); // (3)
$parser->match(TokenType::T_CLOSE_PARENTHESIS); // (3)
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
Expand Down Expand Up @@ -183,23 +183,23 @@ I'll skip the blah and show the code for this function:

public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->firstDateExpression = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_COMMA);
$parser->match(TokenType::T_IDENTIFIER);

$this->intervalExpression = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_IDENTIFIER);

/** @var Lexer $lexer */
$lexer = $parser->getLexer();
$this->unit = $lexer->token['value'];

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
Expand Down
6 changes: 3 additions & 3 deletions docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,12 @@ classes have to implement the base class :

public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
connorhu marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@
</PossiblyUndefinedVariable>
<RedundantConditionGivenDocblockType>
<code>$AST instanceof AST\SelectStatement</code>
<code>$token === Lexer::T_IDENTIFIER</code>
<code>$token === TokenType::T_IDENTIFIER</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Query/ParserResult.php">
Expand Down
8 changes: 4 additions & 4 deletions src/Query/AST/Functions/AbsFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\AST\SimpleArithmeticExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* "ABS" "(" SimpleArithmeticExpression ")"
Expand All @@ -30,11 +30,11 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Query/AST/Functions/BitAndFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace 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;

/**
* "BIT_AND" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
Expand Down Expand Up @@ -36,13 +36,13 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->firstArithmetic = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->secondArithmetic = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Query/AST/Functions/BitOrFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace 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;

/**
* "BIT_OR" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
Expand Down Expand Up @@ -36,13 +36,13 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->firstArithmetic = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->secondArithmetic = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
14 changes: 7 additions & 7 deletions src/Query/AST/Functions/ConcatFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace 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;

/**
* "CONCAT" "(" StringPrimary "," StringPrimary {"," StringPrimary }* ")"
Expand Down Expand Up @@ -42,22 +42,22 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->firstStringPrimary = $parser->StringPrimary();
$this->concatExpressions[] = $this->firstStringPrimary;

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->secondStringPrimary = $parser->StringPrimary();
$this->concatExpressions[] = $this->secondStringPrimary;

while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
while ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$this->concatExpressions[] = $parser->StringPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
8 changes: 4 additions & 4 deletions src/Query/AST/Functions/CurrentDateFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* "CURRENT_DATE"
Expand All @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
8 changes: 4 additions & 4 deletions src/Query/AST/Functions/CurrentTimeFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* "CURRENT_TIME"
Expand All @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
8 changes: 4 additions & 4 deletions src/Query/AST/Functions/CurrentTimestampFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* "CURRENT_TIMESTAMP"
Expand All @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
12 changes: 6 additions & 6 deletions src/Query/AST/Functions/DateAddFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace 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\QueryException;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

use function strtolower;

Expand Down Expand Up @@ -84,15 +84,15 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->firstDateExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->intervalExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->unit = $parser->StringPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Query/AST/Functions/DateDiffFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace 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;

/**
* "DATE_DIFF" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
Expand All @@ -34,13 +34,13 @@ public function getSql(SqlWalker $sqlWalker)
/** @inheritDoc */
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->date1 = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->date2 = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
14 changes: 7 additions & 7 deletions src/Query/AST/Functions/IdentityFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

use function assert;
use function reset;
Expand Down Expand Up @@ -77,20 +77,20 @@ public function getSql(SqlWalker $sqlWalker)
*/
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->pathExpression = $parser->SingleValuedAssociationPathExpression();

if ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
$parser->match(Lexer::T_STRING);
if ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$parser->match(TokenType::T_STRING);

$token = $parser->getLexer()->token;
assert($token !== null);
$this->fieldMapping = $token->value;
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
Loading
Loading