diff --git a/src/Filter.php b/src/Filter.php index 654bcc2..0acff68 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -182,6 +182,34 @@ protected function matchHasValue($rule, $row) return ! empty($this->extractValue($rule->getColumn(), $row)); } + /** + * Create a rule that applies rows where a column has no values, i.e. to all + * rows where this column hasn't been set. + * + * Performs ! isset() | IS NULL actions + * + * @param string $column + * + * @return HasNotValue + */ + public static function hasNotValue($column) + { + return new HasNotValue($column, ''); + } + + /** + * Get whether the given rule's column is null|doesn't contain any values + * + * @param HasNotValue $rule + * @param object $row + * + * @return bool + */ + public function matchHasNotValue(HasNotValue $rule, $row) + { + return ! $this->matchHasValue($rule, $row); + } + /** * Create a rule that matches rows with a column that **equals** the given value * @@ -449,6 +477,8 @@ protected function performMatch(Rule $rule, $row) return $this->matchUnequal($rule, $row); case $rule instanceof HasValue: return $this->matchHasValue($rule, $row); + case $rule instanceof HasNotValue: + return $this->matchHasNotValue($rule, $row); default: throw new InvalidArgumentException(sprintf( 'Unable to match filter. Rule type %s is unknown',