NotCondition.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * Condition that inverts passed [[condition]].
  11. *
  12. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  13. * @since 2.0.14
  14. */
  15. class NotCondition implements ConditionInterface
  16. {
  17. /**
  18. * @var mixed the condition to be negated
  19. */
  20. private $condition;
  21. /**
  22. * NotCondition constructor.
  23. *
  24. * @param mixed $condition the condition to be negated
  25. */
  26. public function __construct($condition)
  27. {
  28. $this->condition = $condition;
  29. }
  30. /**
  31. * @return mixed
  32. */
  33. public function getCondition()
  34. {
  35. return $this->condition;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. * @throws InvalidArgumentException if wrong number of operands have been given.
  40. */
  41. public static function fromArrayDefinition($operator, $operands)
  42. {
  43. if (count($operands) !== 1) {
  44. throw new InvalidArgumentException("Operator '$operator' requires exactly one operand.");
  45. }
  46. return new static(array_shift($operands));
  47. }
  48. }