NotCondition.php 1.3 KB

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