Skip to content

Commit 16e49f6

Browse files
committed
Merge branch '2.14.x' into 3.0.x
* 2.14.x: Add $not constructor parameter to AST classes (doctrine#10267)
2 parents 8c73212 + 5a8541b commit 16e49f6

18 files changed

+259
-96
lines changed

UPGRADE.md

+8
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@ Use `toIterable()` instead.
515515

516516
# Upgrade to 2.14
517517

518+
## Deprecated `Doctrine\ORM\Query\AST\InExpression`
519+
520+
The AST parser will create a `InListExpression` or a `InSubselectExpression` when
521+
encountering an `IN ()` DQL expression instead of a generic `InExpression`.
522+
523+
As a consequence, `SqlWalker::walkInExpression()` has been deprecated in favor of
524+
`SqlWalker::walkInListExpression()` and `SqlWalker::walkInSubselectExpression()`.
525+
518526
## Deprecated constructing a `CacheKey` without `$hash`
519527

520528
The `Doctrine\ORM\Cache\CacheKey` class has an explicit constructor now with

lib/Doctrine/ORM/Query/AST/BetweenExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ class BetweenExpression extends Node
2525
* @param ArithmeticExpression $leftExpr
2626
* @param ArithmeticExpression $rightExpr
2727
*/
28-
public function __construct($expr, $leftExpr, $rightExpr)
28+
public function __construct($expr, $leftExpr, $rightExpr, bool $not = false)
2929
{
3030
$this->expression = $expr;
3131
$this->leftBetweenExpression = $leftExpr;
3232
$this->rightBetweenExpression = $rightExpr;
33+
$this->not = $not;
3334
}
3435

3536
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ class CollectionMemberExpression extends Node
2626
* @param mixed $entityExpr
2727
* @param PathExpression $collValuedPathExpr
2828
*/
29-
public function __construct($entityExpr, $collValuedPathExpr)
29+
public function __construct($entityExpr, $collValuedPathExpr, bool $not = false)
3030
{
3131
$this->entityExpression = $entityExpr;
3232
$this->collectionValuedPathExpression = $collValuedPathExpr;
33+
$this->not = $not;
3334
}
3435

3536
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/ConditionalFactor.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*/
1414
class ConditionalFactor extends Node
1515
{
16-
/** @var bool */
17-
public $not = false;
18-
1916
/** @param ConditionalPrimary $conditionalPrimary */
20-
public function __construct(public $conditionalPrimary)
21-
{
17+
public function __construct(
18+
public $conditionalPrimary,
19+
public bool $not = false,
20+
) {
2221
}
2322

2423
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*/
1414
class EmptyCollectionComparisonExpression extends Node
1515
{
16-
/** @var bool */
17-
public $not;
18-
1916
/** @param PathExpression $expression */
20-
public function __construct(public $expression)
21-
{
17+
public function __construct(
18+
public $expression,
19+
public bool $not = false,
20+
) {
2221
}
2322

2423
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/ExistsExpression.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*/
1414
class ExistsExpression extends Node
1515
{
16-
/** @var bool */
17-
public $not;
18-
1916
/** @param Subselect $subselect */
20-
public function __construct(public $subselect)
21-
{
17+
public function __construct(
18+
public $subselect,
19+
public bool $not = false,
20+
) {
2221
}
2322

2423
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/InExpression.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace Doctrine\ORM\Query\AST;
66

7+
use Doctrine\Deprecations\Deprecation;
78
use Doctrine\ORM\Query\SqlWalker;
89

910
/**
1011
* InExpression ::= ArithmeticExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
1112
*
12-
* @link www.doctrine-project.org
13+
* @deprecated Use {@see InListExpression} or {@see InSubselectExpression} instead.
1314
*/
1415
class InExpression extends Node
1516
{
@@ -25,10 +26,21 @@ class InExpression extends Node
2526
/** @param ArithmeticExpression $expression */
2627
public function __construct(public $expression)
2728
{
29+
if (! $this instanceof InListExpression && ! $this instanceof InSubselectExpression) {
30+
Deprecation::trigger(
31+
'doctrine/orm',
32+
'https://github.com/doctrine/orm/pull/10267',
33+
'%s is deprecated, use %s or %s instead.',
34+
self::class,
35+
InListExpression::class,
36+
InSubselectExpression::class
37+
);
38+
}
2839
}
2940

3041
public function dispatch(SqlWalker $walker): string
3142
{
43+
// We still call the deprecated method in order to not break existing custom SQL walkers.
3244
return $walker->walkInExpression($this);
3345
}
3446
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Query\AST;
6+
7+
class InListExpression extends InExpression
8+
{
9+
/** @var non-empty-list<mixed> */
10+
public $literals;
11+
12+
/** @param non-empty-list<mixed> $literals */
13+
public function __construct(ArithmeticExpression $expression, array $literals, bool $not = false)
14+
{
15+
$this->literals = $literals;
16+
$this->not = $not;
17+
18+
parent::__construct($expression);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\ORM\Query\AST;
6+
7+
class InSubselectExpression extends InExpression
8+
{
9+
/** @var Subselect */
10+
public $subselect;
11+
12+
public function __construct(ArithmeticExpression $expression, Subselect $subselect, bool $not = false)
13+
{
14+
$this->subselect = $subselect;
15+
$this->not = $not;
16+
17+
parent::__construct($expression);
18+
}
19+
}

lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php

+20-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Doctrine\ORM\Query\AST;
66

7+
use Doctrine\Deprecations\Deprecation;
78
use Doctrine\ORM\Query\SqlWalker;
89

10+
use function func_num_args;
11+
912
/**
1013
* InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
1114
* InstanceOfParameter ::= AbstractSchemaName | InputParameter
@@ -14,18 +17,27 @@
1417
*/
1518
class InstanceOfExpression extends Node
1619
{
17-
/** @var bool */
18-
public $not;
19-
2020
/** @var string */
2121
public $identificationVariable;
2222

23-
/** @var mixed[] */
24-
public $value;
23+
/**
24+
* @param string $identVariable
25+
* @param non-empty-list<InputParameter|string> $value
26+
*/
27+
public function __construct(
28+
$identVariable,
29+
public array $value = [],
30+
public bool $not = false
31+
) {
32+
if (func_num_args() < 2) {
33+
Deprecation::trigger(
34+
'doctrine/orm',
35+
'https://github.com/doctrine/orm/pull/10267',
36+
'Not passing a value for $value to %s() is deprecated.',
37+
__METHOD__,
38+
);
39+
}
2540

26-
/** @param string $identVariable */
27-
public function __construct($identVariable)
28-
{
2941
$this->identificationVariable = $identVariable;
3042
}
3143

lib/Doctrine/ORM/Query/AST/LikeExpression.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
*/
1515
class LikeExpression extends Node
1616
{
17-
/** @var bool */
18-
public $not = false;
19-
2017
/**
2118
* @param Node|string $stringExpression
2219
* @param InputParameter|FunctionNode|PathExpression|Literal $stringPattern
2320
* @param Literal|null $escapeChar
2421
*/
25-
public function __construct(public $stringExpression, public $stringPattern, public $escapeChar = null)
26-
{
22+
public function __construct(
23+
public $stringExpression,
24+
public $stringPattern,
25+
public $escapeChar = null,
26+
public bool $not = false,
27+
) {
2728
}
2829

2930
public function dispatch(SqlWalker $walker): string

lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
*/
1414
class NullComparisonExpression extends Node
1515
{
16-
/** @var bool */
17-
public $not;
18-
1916
/** @param Node $expression */
20-
public function __construct(public $expression)
21-
{
17+
public function __construct(
18+
public $expression,
19+
public bool $not = false,
20+
) {
2221
}
2322

2423
public function dispatch(SqlWalker $walker): string

0 commit comments

Comments
 (0)