comparison vendor/doctrine/collections/lib/Doctrine/Common/Collections/ExpressionBuilder.php @ 0:c75dbcec494b

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