123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace Doctrine\Common\Collections;
- use Doctrine\Common\Collections\Expr\Comparison;
- use Doctrine\Common\Collections\Expr\CompositeExpression;
- use Doctrine\Common\Collections\Expr\Value;
- use function func_get_args;
- /**
- * Builder for Expressions in the {@link Selectable} interface.
- *
- * Important Notice for interoperable code: You have to use scalar
- * values only for comparisons, otherwise the behavior of the comparison
- * may be different between implementations (Array vs ORM vs ODM).
- */
- class ExpressionBuilder
- {
- /**
- * @param mixed ...$x
- *
- * @return CompositeExpression
- */
- public function andX($x = null)
- {
- return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
- }
- /**
- * @param mixed ...$x
- *
- * @return CompositeExpression
- */
- public function orX($x = null)
- {
- return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function eq($field, $value)
- {
- return new Comparison($field, Comparison::EQ, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function gt($field, $value)
- {
- return new Comparison($field, Comparison::GT, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function lt($field, $value)
- {
- return new Comparison($field, Comparison::LT, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function gte($field, $value)
- {
- return new Comparison($field, Comparison::GTE, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function lte($field, $value)
- {
- return new Comparison($field, Comparison::LTE, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function neq($field, $value)
- {
- return new Comparison($field, Comparison::NEQ, new Value($value));
- }
- /**
- * @param string $field
- *
- * @return Comparison
- */
- public function isNull($field)
- {
- return new Comparison($field, Comparison::EQ, new Value(null));
- }
- /**
- * @param string $field
- * @param array $values
- *
- * @return Comparison
- */
- public function in($field, array $values)
- {
- return new Comparison($field, Comparison::IN, new Value($values));
- }
- /**
- * @param string $field
- * @param array $values
- *
- * @return Comparison
- */
- public function notIn($field, array $values)
- {
- return new Comparison($field, Comparison::NIN, new Value($values));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function contains($field, $value)
- {
- return new Comparison($field, Comparison::CONTAINS, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function memberOf($field, $value)
- {
- return new Comparison($field, Comparison::MEMBER_OF, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function startsWith($field, $value)
- {
- return new Comparison($field, Comparison::STARTS_WITH, new Value($value));
- }
- /**
- * @param string $field
- * @param mixed $value
- *
- * @return Comparison
- */
- public function endsWith($field, $value)
- {
- return new Comparison($field, Comparison::ENDS_WITH, new Value($value));
- }
- }
|