Comparison.php 1.6 KB

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