BetweenCondition.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\conditions;
  8. use yii\base\InvalidArgumentException;
  9. /**
  10. * Class BetweenCondition represents a `BETWEEN` condition.
  11. *
  12. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  13. * @since 2.0.14
  14. */
  15. class BetweenCondition implements ConditionInterface
  16. {
  17. /**
  18. * @var string $operator the operator to use (e.g. `BETWEEN` or `NOT BETWEEN`)
  19. */
  20. private $operator;
  21. /**
  22. * @var mixed the column name to the left of [[operator]]
  23. */
  24. private $column;
  25. /**
  26. * @var mixed beginning of the interval
  27. */
  28. private $intervalStart;
  29. /**
  30. * @var mixed end of the interval
  31. */
  32. private $intervalEnd;
  33. /**
  34. * Creates a condition with the `BETWEEN` operator.
  35. *
  36. * @param mixed $column the literal to the left of $operator
  37. * @param string $operator the operator to use (e.g. `BETWEEN` or `NOT BETWEEN`)
  38. * @param mixed $intervalStart beginning of the interval
  39. * @param mixed $intervalEnd end of the interval
  40. */
  41. public function __construct($column, $operator, $intervalStart, $intervalEnd)
  42. {
  43. $this->column = $column;
  44. $this->operator = $operator;
  45. $this->intervalStart = $intervalStart;
  46. $this->intervalEnd = $intervalEnd;
  47. }
  48. /**
  49. * @return string
  50. */
  51. public function getOperator()
  52. {
  53. return $this->operator;
  54. }
  55. /**
  56. * @return mixed
  57. */
  58. public function getColumn()
  59. {
  60. return $this->column;
  61. }
  62. /**
  63. * @return mixed
  64. */
  65. public function getIntervalStart()
  66. {
  67. return $this->intervalStart;
  68. }
  69. /**
  70. * @return mixed
  71. */
  72. public function getIntervalEnd()
  73. {
  74. return $this->intervalEnd;
  75. }
  76. /**
  77. * {@inheritdoc}
  78. * @throws InvalidArgumentException if wrong number of operands have been given.
  79. */
  80. public static function fromArrayDefinition($operator, $operands)
  81. {
  82. if (!isset($operands[0], $operands[1], $operands[2])) {
  83. throw new InvalidArgumentException("Operator '$operator' requires three operands.");
  84. }
  85. return new static($operands[0], $operator, $operands[1], $operands[2]);
  86. }
  87. }