Debian Codegraph @

vendor/doctrine/collections/src/ExpressionBuilder.php

raw
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Common\Collections;
6
7 use Doctrine\Common\Collections\Expr\Comparison;
8 use Doctrine\Common\Collections\Expr\CompositeExpression;
9 use Doctrine\Common\Collections\Expr\Expression;
10 use Doctrine\Common\Collections\Expr\Value;
11
12 /**
13 * Builder for Expressions in the {@link Selectable} interface.
14 *
15 * Important Notice for interoperable code: You have to use scalar
16 * values only for comparisons, otherwise the behavior of the comparison
17 * may be different between implementations (Array vs ORM vs ODM).
18 *
19 * @final since 2.5
20 */
21 class ExpressionBuilder
22 {
23 /** @return CompositeExpression */
24 public function andX(Expression ...$expressions)
25 {
26 return new CompositeExpression(CompositeExpression::TYPE_AND, $expressions);
27 }
28
29 /** @return CompositeExpression */
30 public function orX(Expression ...$expressions)
31 {
32 return new CompositeExpression(CompositeExpression::TYPE_OR, $expressions);
33 }
34
35 public function not(Expression $expression): CompositeExpression
36 {
37 return new CompositeExpression(CompositeExpression::TYPE_NOT, [$expression]);
38 }
39
40 /** @return Comparison */
41 public function eq(string $field, mixed $value)
42 {
43 return new Comparison($field, Comparison::EQ, new Value($value));
44 }
45
46 /** @return Comparison */
47 public function gt(string $field, mixed $value)
48 {
49 return new Comparison($field, Comparison::GT, new Value($value));
50 }
51
52 /** @return Comparison */
53 public function lt(string $field, mixed $value)
54 {
55 return new Comparison($field, Comparison::LT, new Value($value));
56 }
57
58 /** @return Comparison */
59 public function gte(string $field, mixed $value)
60 {
61 return new Comparison($field, Comparison::GTE, new Value($value));
62 }
63
64 /** @return Comparison */
65 public function lte(string $field, mixed $value)
66 {
67 return new Comparison($field, Comparison::LTE, new Value($value));
68 }
69
70 /** @return Comparison */
71 public function neq(string $field, mixed $value)
72 {
73 return new Comparison($field, Comparison::NEQ, new Value($value));
74 }
75
76 /** @return Comparison */
77 public function isNull(string $field)
78 {
79 return new Comparison($field, Comparison::EQ, new Value(null));
80 }
81
82 public function isNotNull(string $field): Comparison
83 {
84 return new Comparison($field, Comparison::NEQ, new Value(null));
85 }
86
87 /**
88 * @param mixed[] $values
89 *
90 * @return Comparison
91 */
92 public function in(string $field, array $values)
93 {
94 return new Comparison($field, Comparison::IN, new Value($values));
95 }
96
97 /**
98 * @param mixed[] $values
99 *
100 * @return Comparison
101 */
102 public function notIn(string $field, array $values)
103 {
104 return new Comparison($field, Comparison::NIN, new Value($values));
105 }
106
107 /** @return Comparison */
108 public function contains(string $field, mixed $value)
109 {
110 return new Comparison($field, Comparison::CONTAINS, new Value($value));
111 }
112
113 /** @return Comparison */
114 public function memberOf(string $field, mixed $value)
115 {
116 return new Comparison($field, Comparison::MEMBER_OF, new Value($value));
117 }
118
119 /** @return Comparison */
120 public function startsWith(string $field, mixed $value)
121 {
122 return new Comparison($field, Comparison::STARTS_WITH, new Value($value));
123 }
124
125 /** @return Comparison */
126 public function endsWith(string $field, mixed $value)
127 {
128 return new Comparison($field, Comparison::ENDS_WITH, new Value($value));
129 }
130 }