| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Doctrine\Common\Collections\Expr; |
| 6 |
|
| 7 |
/** |
| 8 |
* Comparison of a field with a value by the given operator. |
| 9 |
* |
| 10 |
* @final since 2.5 |
| 11 |
*/ |
| 12 |
class Comparison implements Expression |
| 13 |
{ |
| 14 |
final public const EQ = '='; |
| 15 |
final public const NEQ = '<>'; |
| 16 |
final public const LT = '<'; |
| 17 |
final public const LTE = '<='; |
| 18 |
final public const GT = '>'; |
| 19 |
final public const GTE = '>='; |
| 20 |
final public const IS = '='; // no difference with EQ |
| 21 |
final public const IN = 'IN'; |
| 22 |
final public const NIN = 'NIN'; |
| 23 |
final public const CONTAINS = 'CONTAINS'; |
| 24 |
final public const MEMBER_OF = 'MEMBER_OF'; |
| 25 |
final public const STARTS_WITH = 'STARTS_WITH'; |
| 26 |
final public const ENDS_WITH = 'ENDS_WITH'; |
| 27 |
|
| 28 |
private readonly Value $value; |
| 29 |
|
| 30 |
public function __construct(private readonly string $field, private readonly string $op, mixed $value) |
| 31 |
{ |
| 32 |
if (! ($value instanceof Value)) { |
| 33 |
$value = new Value($value); |
| 34 |
} |
| 35 |
|
| 36 |
$this->value = $value; |
| 37 |
} |
| 38 |
|
| 39 |
/** @return string */ |
| 40 |
public function getField() |
| 41 |
{ |
| 42 |
return $this->field; |
| 43 |
} |
| 44 |
|
| 45 |
/** @return Value */ |
| 46 |
public function getValue() |
| 47 |
{ |
| 48 |
return $this->value; |
| 49 |
} |
| 50 |
|
| 51 |
/** @return string */ |
| 52 |
public function getOperator() |
| 53 |
{ |
| 54 |
return $this->op; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritDoc} |
| 59 |
*/ |
| 60 |
public function visit(ExpressionVisitor $visitor) |
| 61 |
{ |
| 62 |
return $visitor->walkComparison($this); |
| 63 |
} |
| 64 |
} |