From 65e7f7a8caad9c6b56e1a1ec4fc793028654b652 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 5 Oct 2015 14:01:03 +0200 Subject: [PATCH] FilterExpression: Give the row a chance to dynamically return a value refs #10304 --- .../Icinga/Data/Filter/FilterExpression.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Data/Filter/FilterExpression.php b/library/Icinga/Data/Filter/FilterExpression.php index ca5866a6a..86b36e81c 100644 --- a/library/Icinga/Data/Filter/FilterExpression.php +++ b/library/Icinga/Data/Filter/FilterExpression.php @@ -3,6 +3,8 @@ namespace Icinga\Data\Filter; +use Exception; + class FilterExpression extends Filter { protected $column; @@ -97,22 +99,24 @@ class FilterExpression extends Filter public function matches($row) { - if (! isset($row->{$this->column})) { + try { + $rowValue = $row->{$this->column}; + } catch (Exception $e) { // TODO: REALLY? Exception? return false; } if (is_array($this->expression)) { - return in_array($row->{$this->column}, $this->expression); + return in_array($rowValue, $this->expression); } $expression = (string) $this->expression; if (strpos($expression, '*') === false) { - if (is_array($row->{$this->column})) { - return in_array($expression, $row->{$this->column}); + if (is_array($rowValue)) { + return in_array($expression, $rowValue); } - return (string) $row->{$this->column} === $expression; + return (string) $rowValue === $expression; } $parts = array(); @@ -121,8 +125,8 @@ class FilterExpression extends Filter } $pattern = '/^' . implode('.*', $parts) . '$/'; - if (is_array($row->{$this->column})) { - foreach ($row->{$this->column} as $candidate) { + if (is_array($rowValue)) { + foreach ($rowValue as $candidate) { if (preg_match($pattern, $candidate)) { return true; } @@ -131,7 +135,7 @@ class FilterExpression extends Filter return false; } - return (bool) preg_match($pattern, $row->{$this->column}); + return (bool) preg_match($pattern, $rowValue); } public function andFilter(Filter $filter)