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.
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>.
20 namespace Doctrine\Common\Collections
;
22 use Doctrine\Common\Collections\Expr\Comparison
;
23 use Doctrine\Common\Collections\Expr\CompositeExpression
;
24 use Doctrine\Common\Collections\Expr\Value
;
27 * Builder for Expressions in the {@link Selectable} interface.
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).
33 * @author Benjamin Eberlei <kontakt@beberlei.de>
36 class ExpressionBuilder
41 * @return CompositeExpression
43 public function andX($x = null)
45 return new CompositeExpression(CompositeExpression
::TYPE_AND
, func_get_args());
51 * @return CompositeExpression
53 public function orX($x = null)
55 return new CompositeExpression(CompositeExpression
::TYPE_OR
, func_get_args());
59 * @param string $field
64 public function eq($field, $value)
66 return new Comparison($field, Comparison
::EQ
, new Value($value));
70 * @param string $field
75 public function gt($field, $value)
77 return new Comparison($field, Comparison
::GT
, new Value($value));
81 * @param string $field
86 public function lt($field, $value)
88 return new Comparison($field, Comparison
::LT
, new Value($value));
92 * @param string $field
97 public function gte($field, $value)
99 return new Comparison($field, Comparison
::GTE
, new Value($value));
103 * @param string $field
104 * @param mixed $value
108 public function lte($field, $value)
110 return new Comparison($field, Comparison
::LTE
, new Value($value));
114 * @param string $field
115 * @param mixed $value
119 public function neq($field, $value)
121 return new Comparison($field, Comparison
::NEQ
, new Value($value));
125 * @param string $field
129 public function isNull($field)
131 return new Comparison($field, Comparison
::EQ
, new Value(null));
135 * @param string $field
136 * @param mixed $values
140 public function in($field, array $values)
142 return new Comparison($field, Comparison
::IN
, new Value($values));
146 * @param string $field
147 * @param mixed $values
151 public function notIn($field, array $values)
153 return new Comparison($field, Comparison
::NIN
, new Value($values));
157 * @param string $field
158 * @param mixed $value
162 public function contains($field, $value)
164 return new Comparison($field, Comparison
::CONTAINS
, new Value($value));