Skip to content

Commit 73f0052

Browse files
vjikTigrov
andauthored
Remove "Condition" suffix from condition classes (#1006)
Co-authored-by: Sergei Tigrov <[email protected]>
1 parent 333f44d commit 73f0052

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+275
-305
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@
107107
- Enh #991: Improve types in `ConnectionInterface::transaction()` (@kikara)
108108
- Chg #998: Add `yiisoft/db-implementation` virtual package as dependency (@vjik)
109109
- Chg #999: Remove `requireTransaction()` method and `$isolationLevel` property from `AbstractCommand` (@vjik)
110-
- Enh #1000: Prepare values in `HashCondition` (@vjik)
110+
- Enh #1000: Prepare values in `Columns` (@vjik)
111111
- Chg #1001: Remove `ParamInterface` (@vjik)
112112
- Chg #1001: Add public properties `$type` and `$value` to `Param` class instead of `getType()` and `getValue()` methods that were removed (@vjik)
113113
- Chg #1002: Remove specific condition interfaces (@vjik)
114-
- Chg #1003: Refactor namespace of condition objects and use promoted properties instead of getters (@vjik)
114+
- Chg #1003, #1006: Refactor namespace of condition objects and use promoted properties instead of getters (@vjik)
115115

116116
## 1.3.0 March 21, 2024
117117

docs/guide/en/query/where.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `Yiisoft\Db\Query\Query::where()` method specifies the `WHERE` fragment of a
44
You can use one of the four formats to specify a `WHERE` condition.
55

66
- string format, `status=1`.
7-
- hash format, `['status' => 1, 'type' => 2]`.
7+
- key-value format, `['status' => 1, 'type' => 2]`.
88
- operator format, `['like', 'name', 'test']`.
99
- object format, `new LikeCondition('name', 'LIKE', 'test')`.
1010

@@ -60,7 +60,7 @@ WHERE (`status` = 10) AND (`type` IS NULL) AND (`id` IN (4, 8, 15))
6060

6161
As you can see, the query builder is intelligent enough to handle values that are nulls or arrays.
6262

63-
You can also use subqueries with hash format like the following.
63+
You can also use subqueries with key-value format like the following.
6464

6565
```php
6666
use Yiisoft\Db\Connection\ConnectionInterface;
@@ -78,7 +78,7 @@ The relevant part of SQL is:
7878
WHERE `id` IN (SELECT `id` FROM `user`)
7979
```
8080

81-
Using the hash format, Yii DB internally applies parameter binding for values, so in contrast to the string format,
81+
Using the key-value format, Yii DB internally applies parameter binding for values, so in contrast to the string format,
8282
here you don't have to add parameters manually.
8383

8484
However, note that Yii DB never escapes column names, so if you pass a variable obtained from the user side as a column
@@ -104,7 +104,7 @@ Operator format allows you to specify arbitrary conditions in a programmatic way
104104
['operator', 'operand1', 'operand2', ...]
105105
```
106106

107-
Where the operands can each be specified in string format, hash format or operator format recursively,
107+
Where the operands can each be specified in string format, key-value format or operator format recursively,
108108
while the operator can be one of the following:
109109

110110
### and
@@ -276,16 +276,16 @@ Internally, the formats described are implicitly converted to object format befo
276276
so it's possible to combine formats in a single condition:
277277

278278
```php
279-
use Yiisoft\Db\QueryBuilder\Condition\InCondition;
280-
use Yiisoft\Db\QueryBuilder\Condition\OrCondition;
279+
use Yiisoft\Db\QueryBuilder\Condition\In;
280+
use Yiisoft\Db\QueryBuilder\Condition\OrX;
281281
use Yiisoft\Db\Query\Query;
282282

283283
/** @var Query $query */
284284

285285
$query->andWhere(
286-
new OrCondition(
286+
new OrX(
287287
[
288-
new InCondition('type', 'in', $types),
288+
new In('type', 'in', $types),
289289
['like', 'name', '%good%'],
290290
'disabled=false',
291291
],
@@ -297,12 +297,13 @@ Conversion from operator format into object format is performed according
297297
to `Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder::conditionClasses` property
298298
that maps operator names to representative class names.
299299

300-
- `AND`, `OR` => `Yiisoft\Db\QueryBuilder\Condition\ConjunctionCondition`;
301-
- `NOT` => `Yiisoft\Db\QueryBuilder\Condition\NotCondition`;
302-
- `IN`, `NOT IN` => `Yiisoft\Db\QueryBuilder\Condition\InCondition`;
303-
- `BETWEEN`, `NOT BETWEEN` => `Yiisoft\Db\QueryBuilder\Condition\BetweenCondition`;
304-
- `ARRAY OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\ArrayOverlapsCondition`;
305-
- `JSON OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition`.
300+
- `AND` => `Yiisoft\Db\QueryBuilder\Condition\AndX`;
301+
- `OR` => `Yiisoft\Db\QueryBuilder\Condition\OrX`;
302+
- `NOT` => `Yiisoft\Db\QueryBuilder\Condition\Not`;
303+
- `IN`, `NOT IN` => `Yiisoft\Db\QueryBuilder\Condition\In`;
304+
- `BETWEEN`, `NOT BETWEEN` => `Yiisoft\Db\QueryBuilder\Condition\Between`;
305+
- `ARRAY OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\ArrayOverlaps`;
306+
- `JSON OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\JsonOverlaps`.
306307

307308
## Appending conditions
308309

@@ -343,7 +344,7 @@ $query->filterWhere(['username' => $username, 'email' => $email]);
343344
```
344345

345346
The only difference between `Yiisoft\Db\Query\Query::filterWhere()` and `Yiisoft\Db\Query\Query::where()`
346-
is that the former will ignore empty values provided in the condition in hash format.
347+
is that the former will ignore empty values provided in the condition in key-value format.
347348

348349
So, if `$email` is empty while `$username` isn't,
349350
the above code will result in the SQL condition `WHERE username=:username`.

docs/guide/pt-BR/query/where.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,16 @@ Internamente, os formatos descritos são convertidos implicitamente para o forma
251251
então é possível combinar formatos em uma única condição:
252252

253253
```php
254-
use Yiisoft\Db\QueryBuilder\Condition\InCondition;
255-
use Yiisoft\Db\QueryBuilder\Condition\OrCondition;
254+
use Yiisoft\Db\QueryBuilder\Condition\In;
255+
use Yiisoft\Db\QueryBuilder\Condition\OrX;
256256
use Yiisoft\Db\Query\Query;
257257

258258
/** @var Query $query */
259259

260260
$query->andWhere(
261-
new OrCondition(
261+
new OrX(
262262
[
263-
new InCondition('type', 'in', $types),
263+
new In('type', 'in', $types),
264264
['like', 'name', '%good%'],
265265
'disabled=false',
266266
],
@@ -272,10 +272,13 @@ A conversão do formato operador para o formato objeto é realizada de acordo
272272
com a propriedade `Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder::conditionClasses`
273273
que mapeia nomes de operadores para nomes de classes representativos.
274274

275-
- `AND`, `OR` => `Yiisoft\Db\QueryBuilder\Condition\ConjunctionCondition`.
276-
- `NOT` => `Yiisoft\Db\QueryBuilder\Condition\NotCondition`.
277-
- `IN`, `NOT IN` => `Yiisoft\Db\QueryBuilder\Condition\InCondition`.
278-
- `BETWEEN`, `NOT BETWEEN` => `Yiisoft\Db\QueryBuilder\Condition\BetweenCondition`.
275+
- `AND` => `Yiisoft\Db\QueryBuilder\Condition\AndX`;
276+
- `OR` => `Yiisoft\Db\QueryBuilder\Condition\OrX`;
277+
- `NOT` => `Yiisoft\Db\QueryBuilder\Condition\Not`;
278+
- `IN`, `NOT IN` => `Yiisoft\Db\QueryBuilder\Condition\In`;
279+
- `BETWEEN`, `NOT BETWEEN` => `Yiisoft\Db\QueryBuilder\Condition\Between`;
280+
- `ARRAY OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\ArrayOverlaps`;
281+
- `JSON OVERLAPS` => `Yiisoft\Db\QueryBuilder\Condition\JsonOverlaps`.
279282

280283
## Anexando condições
281284

src/Query/Query.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,7 @@ private function filterCondition(array|string $condition): array|string
882882

883883
if (!isset($condition[0])) {
884884
/**
885-
* Hash format: 'column1' => 'value1', 'column2' => 'value2', ...
886-
*
887-
* @psalm-var mixed $value
885+
* Key-value format: 'column1' => 'value1', 'column2' => 'value2', ...
888886
*/
889887
foreach ($condition as $name => $value) {
890888
if ($this->isEmpty($value)) {

src/Query/QueryPartsInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,10 @@ public function union(QueryInterface|string $sql, bool $all = false): static;
644644
*
645645
* The `$condition` specified as an array can be in one of the following two formats:
646646
*
647-
* - hash format: `['column1' => value1, 'column2' => value2, ...]`
647+
* - key-value format: `['column1' => value1, 'column2' => value2, ...]`
648648
* - operator format: `[operator, operand1, operand2, ...]`
649649
*
650-
* A condition in hash format represents the following SQL expression in general:
650+
* A condition in key-value format represents the following SQL expression in general:
651651
* `column1=value1 AND column2=value2 AND ...`. In case when a value is an array,
652652
* an `IN` expression will be generated. And if a value is `null`, `IS NULL` will be used in the generated
653653
* expression. Below are some examples:

src/QueryBuilder/AbstractDQLQueryBuilder.php

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
use Yiisoft\Db\Expression\CaseExpressionBuilder;
2323
use Yiisoft\Db\Expression\StructuredExpression;
2424
use Yiisoft\Db\Expression\StructuredExpressionBuilder;
25-
use Yiisoft\Db\QueryBuilder\Condition\HashCondition;
25+
use Yiisoft\Db\QueryBuilder\Condition\Columns;
2626
use Yiisoft\Db\QueryBuilder\Condition\ConditionInterface;
27-
use Yiisoft\Db\QueryBuilder\Condition\SimpleCondition;
27+
use Yiisoft\Db\QueryBuilder\Condition\Simple;
2828
use Yiisoft\Db\Query\Query;
2929
use Yiisoft\Db\Query\QueryExpressionBuilder;
3030
use Yiisoft\Db\Query\QueryInterface;
@@ -445,12 +445,15 @@ public function createConditionFromArray(array $condition): ConditionInterface
445445
/** operator format: operator, operand 1, operand 2, ... */
446446
if (isset($condition[0])) {
447447
$operator = strtoupper((string) array_shift($condition));
448-
$className = $this->conditionClasses[$operator] ?? SimpleCondition::class;
448+
$className = $this->conditionClasses[$operator] ?? Simple::class;
449449
return $className::fromArrayDefinition($operator, $condition);
450450
}
451451

452-
/** hash format: 'column1' => 'value1', 'column2' => 'value2', ... */
453-
return new HashCondition($condition);
452+
/**
453+
* Key-value format: 'column1' => 'value1', 'column2' => 'value2', ...
454+
* @psalm-var array<string, mixed> $condition
455+
*/
456+
return new Columns($condition);
454457
}
455458

456459
public function getExpressionBuilder(ExpressionInterface $expression): object
@@ -503,21 +506,21 @@ public function setSeparator(string $separator): void
503506
protected function defaultConditionClasses(): array
504507
{
505508
return [
506-
'NOT' => Condition\NotCondition::class,
507-
'AND' => Condition\AndCondition::class,
508-
'OR' => Condition\OrCondition::class,
509-
'BETWEEN' => Condition\BetweenCondition::class,
510-
'NOT BETWEEN' => Condition\BetweenCondition::class,
511-
'IN' => Condition\InCondition::class,
512-
'NOT IN' => Condition\InCondition::class,
513-
'LIKE' => Condition\LikeCondition::class,
514-
'NOT LIKE' => Condition\LikeCondition::class,
515-
'OR LIKE' => Condition\LikeCondition::class,
516-
'OR NOT LIKE' => Condition\LikeCondition::class,
517-
'EXISTS' => Condition\ExistsCondition::class,
518-
'NOT EXISTS' => Condition\ExistsCondition::class,
519-
'ARRAY OVERLAPS' => Condition\ArrayOverlapsCondition::class,
520-
'JSON OVERLAPS' => Condition\JsonOverlapsCondition::class,
509+
'NOT' => Condition\Not::class,
510+
'AND' => Condition\AndX::class,
511+
'OR' => Condition\OrX::class,
512+
'BETWEEN' => Condition\Between::class,
513+
'NOT BETWEEN' => Condition\Between::class,
514+
'IN' => Condition\In::class,
515+
'NOT IN' => Condition\In::class,
516+
'LIKE' => Condition\Like::class,
517+
'NOT LIKE' => Condition\Like::class,
518+
'OR LIKE' => Condition\Like::class,
519+
'OR NOT LIKE' => Condition\Like::class,
520+
'EXISTS' => Condition\Exists::class,
521+
'NOT EXISTS' => Condition\Exists::class,
522+
'ARRAY OVERLAPS' => Condition\ArrayOverlaps::class,
523+
'JSON OVERLAPS' => Condition\JsonOverlaps::class,
521524
];
522525
}
523526

@@ -536,16 +539,16 @@ protected function defaultExpressionBuilders(): array
536539
Query::class => QueryExpressionBuilder::class,
537540
Param::class => ParamBuilder::class,
538541
Expression::class => ExpressionBuilder::class,
539-
Condition\NotCondition::class => Condition\Builder\NotConditionBuilder::class,
540-
Condition\AndCondition::class => Condition\Builder\LogicalConditionBuilder::class,
541-
Condition\OrCondition::class => Condition\Builder\LogicalConditionBuilder::class,
542-
Condition\BetweenCondition::class => Condition\Builder\BetweenConditionBuilder::class,
543-
Condition\InCondition::class => Condition\Builder\InConditionBuilder::class,
544-
Condition\LikeCondition::class => Condition\Builder\LikeConditionBuilder::class,
545-
Condition\ExistsCondition::class => Condition\Builder\ExistsConditionBuilder::class,
546-
SimpleCondition::class => Condition\Builder\SimpleConditionBuilder::class,
547-
HashCondition::class => Condition\Builder\HashConditionBuilder::class,
548-
Condition\BetweenColumnsCondition::class => Condition\Builder\BetweenColumnsConditionBuilder::class,
542+
Condition\Not::class => Condition\Builder\NotBuilder::class,
543+
Condition\AndX::class => Condition\Builder\LogicalBuilder::class,
544+
Condition\OrX::class => Condition\Builder\LogicalBuilder::class,
545+
Condition\Between::class => Condition\Builder\BetweenBuilder::class,
546+
Condition\In::class => Condition\Builder\InBuilder::class,
547+
Condition\Like::class => Condition\Builder\LikeBuilder::class,
548+
Condition\Exists::class => Condition\Builder\ExistsBuilder::class,
549+
Simple::class => Condition\Builder\SimpleBuilder::class,
550+
Columns::class => Condition\Builder\ColumnsBuilder::class,
551+
Condition\BetweenColumns::class => Condition\Builder\BetweenColumnsBuilder::class,
549552
JsonExpression::class => JsonExpressionBuilder::class,
550553
ArrayExpression::class => ArrayExpressionBuilder::class,
551554
StructuredExpression::class => StructuredExpressionBuilder::class,

src/QueryBuilder/Condition/AbstractOverlapsCondition.php renamed to src/QueryBuilder/Condition/AbstractOverlaps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* The base class for classes representing the array and JSON overlaps conditions.
1515
*/
16-
abstract class AbstractOverlapsCondition implements ConditionInterface
16+
abstract class AbstractOverlaps implements ConditionInterface
1717
{
1818
/**
1919
* @param ExpressionInterface|string $column The column name or an expression.

src/QueryBuilder/Condition/OrCondition.php renamed to src/QueryBuilder/Condition/AndX.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Condition that connects two or more SQL expressions with the `AND` operator.
1111
*/
12-
final class OrCondition implements ConditionInterface
12+
final class AndX implements ConditionInterface
1313
{
1414
/**
1515
* @param array $expressions The expressions that are connected by this condition.

src/QueryBuilder/Condition/ArrayOverlapsCondition.php renamed to src/QueryBuilder/Condition/ArrayOverlaps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/**
88
* Condition that represents `ARRAY OVERLAPS` operator is used to check if a column of array type overlaps another array.
99
*/
10-
final class ArrayOverlapsCondition extends AbstractOverlapsCondition
10+
final class ArrayOverlaps extends AbstractOverlaps
1111
{
1212
}

src/QueryBuilder/Condition/BetweenCondition.php renamed to src/QueryBuilder/Condition/Between.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Condition that's represented `BETWEEN` operator is used to check if a value is between two values.
1212
*/
13-
final class BetweenCondition implements ConditionInterface
13+
final class Between implements ConditionInterface
1414
{
1515
/**
1616
* @param ExpressionInterface|string $column The column name.

0 commit comments

Comments
 (0)