BetweenCondition.php 2.4 KB

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