Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@0
|
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@0
|
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@0
|
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
Chris@0
|
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
Chris@0
|
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
Chris@0
|
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
Chris@0
|
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
Chris@0
|
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
Chris@0
|
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
Chris@0
|
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@0
|
14 *
|
Chris@0
|
15 * This software consists of voluntary contributions made by many individuals
|
Chris@0
|
16 * and is licensed under the MIT license. For more information, see
|
Chris@0
|
17 * <http://www.doctrine-project.org>.
|
Chris@0
|
18 */
|
Chris@0
|
19
|
Chris@0
|
20 namespace Doctrine\Common\Collections;
|
Chris@0
|
21
|
Chris@0
|
22 use Doctrine\Common\Collections\Expr\Comparison;
|
Chris@0
|
23 use Doctrine\Common\Collections\Expr\CompositeExpression;
|
Chris@0
|
24 use Doctrine\Common\Collections\Expr\Value;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Builder for Expressions in the {@link Selectable} interface.
|
Chris@0
|
28 *
|
Chris@0
|
29 * Important Notice for interoperable code: You have to use scalar
|
Chris@12
|
30 * values only for comparisons, otherwise the behavior of the comparison
|
Chris@0
|
31 * may be different between implementations (Array vs ORM vs ODM).
|
Chris@0
|
32 *
|
Chris@0
|
33 * @author Benjamin Eberlei <kontakt@beberlei.de>
|
Chris@0
|
34 * @since 2.3
|
Chris@0
|
35 */
|
Chris@0
|
36 class ExpressionBuilder
|
Chris@0
|
37 {
|
Chris@0
|
38 /**
|
Chris@0
|
39 * @param mixed $x
|
Chris@0
|
40 *
|
Chris@0
|
41 * @return CompositeExpression
|
Chris@0
|
42 */
|
Chris@0
|
43 public function andX($x = null)
|
Chris@0
|
44 {
|
Chris@0
|
45 return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 /**
|
Chris@0
|
49 * @param mixed $x
|
Chris@0
|
50 *
|
Chris@0
|
51 * @return CompositeExpression
|
Chris@0
|
52 */
|
Chris@0
|
53 public function orX($x = null)
|
Chris@0
|
54 {
|
Chris@0
|
55 return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * @param string $field
|
Chris@0
|
60 * @param mixed $value
|
Chris@0
|
61 *
|
Chris@0
|
62 * @return Comparison
|
Chris@0
|
63 */
|
Chris@0
|
64 public function eq($field, $value)
|
Chris@0
|
65 {
|
Chris@0
|
66 return new Comparison($field, Comparison::EQ, new Value($value));
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * @param string $field
|
Chris@0
|
71 * @param mixed $value
|
Chris@0
|
72 *
|
Chris@0
|
73 * @return Comparison
|
Chris@0
|
74 */
|
Chris@0
|
75 public function gt($field, $value)
|
Chris@0
|
76 {
|
Chris@0
|
77 return new Comparison($field, Comparison::GT, new Value($value));
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * @param string $field
|
Chris@0
|
82 * @param mixed $value
|
Chris@0
|
83 *
|
Chris@0
|
84 * @return Comparison
|
Chris@0
|
85 */
|
Chris@0
|
86 public function lt($field, $value)
|
Chris@0
|
87 {
|
Chris@0
|
88 return new Comparison($field, Comparison::LT, new Value($value));
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 /**
|
Chris@0
|
92 * @param string $field
|
Chris@0
|
93 * @param mixed $value
|
Chris@0
|
94 *
|
Chris@0
|
95 * @return Comparison
|
Chris@0
|
96 */
|
Chris@0
|
97 public function gte($field, $value)
|
Chris@0
|
98 {
|
Chris@0
|
99 return new Comparison($field, Comparison::GTE, new Value($value));
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 /**
|
Chris@0
|
103 * @param string $field
|
Chris@0
|
104 * @param mixed $value
|
Chris@0
|
105 *
|
Chris@0
|
106 * @return Comparison
|
Chris@0
|
107 */
|
Chris@0
|
108 public function lte($field, $value)
|
Chris@0
|
109 {
|
Chris@0
|
110 return new Comparison($field, Comparison::LTE, new Value($value));
|
Chris@0
|
111 }
|
Chris@0
|
112
|
Chris@0
|
113 /**
|
Chris@0
|
114 * @param string $field
|
Chris@0
|
115 * @param mixed $value
|
Chris@0
|
116 *
|
Chris@0
|
117 * @return Comparison
|
Chris@0
|
118 */
|
Chris@0
|
119 public function neq($field, $value)
|
Chris@0
|
120 {
|
Chris@0
|
121 return new Comparison($field, Comparison::NEQ, new Value($value));
|
Chris@0
|
122 }
|
Chris@0
|
123
|
Chris@0
|
124 /**
|
Chris@0
|
125 * @param string $field
|
Chris@0
|
126 *
|
Chris@0
|
127 * @return Comparison
|
Chris@0
|
128 */
|
Chris@0
|
129 public function isNull($field)
|
Chris@0
|
130 {
|
Chris@0
|
131 return new Comparison($field, Comparison::EQ, new Value(null));
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@0
|
134 /**
|
Chris@0
|
135 * @param string $field
|
Chris@0
|
136 * @param mixed $values
|
Chris@0
|
137 *
|
Chris@0
|
138 * @return Comparison
|
Chris@0
|
139 */
|
Chris@0
|
140 public function in($field, array $values)
|
Chris@0
|
141 {
|
Chris@0
|
142 return new Comparison($field, Comparison::IN, new Value($values));
|
Chris@0
|
143 }
|
Chris@0
|
144
|
Chris@0
|
145 /**
|
Chris@0
|
146 * @param string $field
|
Chris@0
|
147 * @param mixed $values
|
Chris@0
|
148 *
|
Chris@0
|
149 * @return Comparison
|
Chris@0
|
150 */
|
Chris@0
|
151 public function notIn($field, array $values)
|
Chris@0
|
152 {
|
Chris@0
|
153 return new Comparison($field, Comparison::NIN, new Value($values));
|
Chris@0
|
154 }
|
Chris@0
|
155
|
Chris@0
|
156 /**
|
Chris@0
|
157 * @param string $field
|
Chris@0
|
158 * @param mixed $value
|
Chris@0
|
159 *
|
Chris@0
|
160 * @return Comparison
|
Chris@0
|
161 */
|
Chris@0
|
162 public function contains($field, $value)
|
Chris@0
|
163 {
|
Chris@0
|
164 return new Comparison($field, Comparison::CONTAINS, new Value($value));
|
Chris@0
|
165 }
|
Chris@12
|
166
|
Chris@12
|
167 /**
|
Chris@12
|
168 * @param string $field
|
Chris@12
|
169 * @param mixed $value
|
Chris@12
|
170 *
|
Chris@12
|
171 * @return Comparison
|
Chris@12
|
172 */
|
Chris@12
|
173 public function memberOf ($field, $value)
|
Chris@12
|
174 {
|
Chris@12
|
175 return new Comparison($field, Comparison::MEMBER_OF, new Value($value));
|
Chris@12
|
176 }
|
Chris@12
|
177
|
Chris@12
|
178 /**
|
Chris@12
|
179 * @param string $field
|
Chris@12
|
180 * @param mixed $value
|
Chris@12
|
181 *
|
Chris@12
|
182 * @return Comparison
|
Chris@12
|
183 */
|
Chris@12
|
184 public function startsWith($field, $value)
|
Chris@12
|
185 {
|
Chris@12
|
186 return new Comparison($field, Comparison::STARTS_WITH, new Value($value));
|
Chris@12
|
187 }
|
Chris@12
|
188
|
Chris@12
|
189 /**
|
Chris@12
|
190 * @param string $field
|
Chris@12
|
191 * @param mixed $value
|
Chris@12
|
192 *
|
Chris@12
|
193 * @return Comparison
|
Chris@12
|
194 */
|
Chris@12
|
195 public function endsWith($field, $value)
|
Chris@12
|
196 {
|
Chris@12
|
197 return new Comparison($field, Comparison::ENDS_WITH, new Value($value));
|
Chris@12
|
198 }
|
Chris@12
|
199
|
Chris@0
|
200 }
|