From f27ee491821a31abdd0efcffa198cae845763be9 Mon Sep 17 00:00:00 2001 From: Andrei Gorgan Date: Tue, 5 Feb 2019 20:43:09 +0200 Subject: [PATCH 1/7] Added getters for ValuePath properties --- src/Ast/ValuePath.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Ast/ValuePath.php b/src/Ast/ValuePath.php index d708316..a879b42 100644 --- a/src/Ast/ValuePath.php +++ b/src/Ast/ValuePath.php @@ -29,6 +29,22 @@ public function __construct(AttributePath $attributePath, Filter $filter) $this->filter = $filter; } + /** + * @return AttributePath + */ + public function getAttributePath() + { + return $this->attributePath; + } + + /** + * @return Filter + */ + public function getFilter() + { + return $this->filter; + } + public function __toString() { return sprintf('%s[%s]', $this->attributePath, $this->filter); From 706c2137e8545ae4cf1c47292cc1bf54c0be99f4 Mon Sep 17 00:00:00 2001 From: Andrei Gorgan Date: Tue, 5 Feb 2019 21:19:37 +0200 Subject: [PATCH 2/7] Added getters for ValuePath properties --- src/Ast/ValuePath.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Ast/ValuePath.php b/src/Ast/ValuePath.php index a879b42..c058d78 100644 --- a/src/Ast/ValuePath.php +++ b/src/Ast/ValuePath.php @@ -47,15 +47,15 @@ public function getFilter() public function __toString() { - return sprintf('%s[%s]', $this->attributePath, $this->filter); + return sprintf('%s[%s]', $this->getAttributePath(), $this->getFilter()); } public function dump() { return [ 'ValuePath' => [ - $this->attributePath->dump(), - $this->filter->dump(), + $this->getAttributePath()->dump(), + $this->getFilter()->dump(), ], ]; } From 6e988b73f951453d730f1a390f144108d74c0a7c Mon Sep 17 00:00:00 2001 From: Alina Berce Date: Mon, 12 Aug 2019 16:12:08 +0300 Subject: [PATCH 3/7] Add getters for Path attributes --- src/Ast/Path.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Ast/Path.php b/src/Ast/Path.php index d897c00..a7471fa 100644 --- a/src/Ast/Path.php +++ b/src/Ast/Path.php @@ -64,4 +64,20 @@ public function dump() return array_merge($this->valuePath->dump(), $this->attributePath->dump()); } } + + /** + * @return AttributePath + */ + public function getAttributePath() + { + return $this->attributePath; + } + + /** + * @return ValuePath + */ + public function getValuePath() + { + return $this->valuePath; + } } From 9f816d61b3127ae10e47814ef4e2e93ad65fdbf8 Mon Sep 17 00:00:00 2001 From: Alina Berce Date: Fri, 11 Oct 2019 17:34:29 +0300 Subject: [PATCH 4/7] Fix scim filtering to allow multiple or conditions --- src/Ast/Disjunction.php | 10 +++++----- tests/ParserFilterModeTest.php | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Ast/Disjunction.php b/src/Ast/Disjunction.php index 97c1ede..7df649a 100644 --- a/src/Ast/Disjunction.php +++ b/src/Ast/Disjunction.php @@ -13,11 +13,11 @@ class Disjunction extends Filter { - /** @var Term[] */ + /** @var Filter[] */ private $terms = []; /** - * @param Term[] $terms + * @param Filter[] $terms */ public function __construct(array $terms = []) { @@ -27,15 +27,15 @@ public function __construct(array $terms = []) } /** - * @param Term $term + * @param Filter $term */ - public function add(Term $term) + public function add(Filter $term) { $this->terms[] = $term; } /** - * @return Term[] + * @return Filter[] */ public function getTerms() { diff --git a/tests/ParserFilterModeTest.php b/tests/ParserFilterModeTest.php index c7bb873..6ddbf41 100644 --- a/tests/ParserFilterModeTest.php +++ b/tests/ParserFilterModeTest.php @@ -218,7 +218,23 @@ public function parser_provider_v2() ] ] ], - + [ + 'username eq "john" and ((name sw "mike" or id ew "123") or name eq "alina")', + [ + 'Conjunction' => [ + ['ComparisonExpression' => 'username eq john'], + [ + 'Disjunction' => [ + 'Disjunction' => [ + ['ComparisonExpression' => 'name sw mike'], + ['ComparisonExpression' => 'id ew 123'], + ], + ['ComparisonExpression' => 'name eq alina'] + ] + ] + ] + ] + ], [ 'username eq "john" and not (name sw "mike" or id ew "123")', [ From bd990295ff263e623211b8bf94dec44f35cf275e Mon Sep 17 00:00:00 2001 From: Alina Berce Date: Fri, 11 Oct 2019 17:51:30 +0300 Subject: [PATCH 5/7] Fix scim filtering to allow multiple or conditions --- tests/ParserFilterModeTest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/ParserFilterModeTest.php b/tests/ParserFilterModeTest.php index 6ddbf41..61a453d 100644 --- a/tests/ParserFilterModeTest.php +++ b/tests/ParserFilterModeTest.php @@ -219,19 +219,21 @@ public function parser_provider_v2() ] ], [ - 'username eq "john" and ((name sw "mike" or id ew "123") or name eq "alina")', + '((name eq "mike" or id eq "123") or name eq "alina") and username eq "john"', [ 'Conjunction' => [ - ['ComparisonExpression' => 'username eq john'], [ 'Disjunction' => [ - 'Disjunction' => [ - ['ComparisonExpression' => 'name sw mike'], - ['ComparisonExpression' => 'id ew 123'], + [ + 'Disjunction' => [ + ['ComparisonExpression' => 'name eq mike'], + ['ComparisonExpression' => 'id eq 123'], + ] ], ['ComparisonExpression' => 'name eq alina'] ] - ] + ], + ['ComparisonExpression' => 'username eq john'] ] ] ], @@ -261,6 +263,7 @@ public function test_parser_v2($filterString, array $expectedDump) { $parser = $this->getParser(); $node = $parser->parse($filterString); + $this->assertEquals($expectedDump, $node->dump(), sprintf("\n\n%s\n%s\n\n", $filterString, json_encode($node->dump(), JSON_PRETTY_PRINT))); } From 5799fd1a37b1d598aa617ec8261299fa241d9483 Mon Sep 17 00:00:00 2001 From: Andrei Gorgan Date: Tue, 4 Feb 2020 20:57:08 +0200 Subject: [PATCH 6/7] Added possibility to chain multiple comparision expressions in a conjunction or a disjunction --- src/Parser.php | 10 +++++-- tests/ParserFilterModeTest.php | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 992f8ba..d34cb13 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -127,13 +127,16 @@ private function disjunction() $terms = []; $terms[] = $this->conjunction(); - if ($this->lexer->isNextToken(Tokens::T_SP)) { + $isNextTokenOr = true; + while($this->lexer->isNextToken(Tokens::T_SP) && $isNextTokenOr) { $nextToken = $this->lexer->glimpse(); if ($this->isName('or', $nextToken)) { $this->match(Tokens::T_SP); $this->match(Tokens::T_NAME); $this->match(Tokens::T_SP); $terms[] = $this->conjunction(); + } else { + $isNextTokenOr = false; } } @@ -152,13 +155,16 @@ private function conjunction() $factors = []; $factors[] = $this->factor(); - if ($this->lexer->isNextToken(Tokens::T_SP)) { + $isNextTokenAnd = true; + while($this->lexer->isNextToken(Tokens::T_SP) && $isNextTokenAnd) { $nextToken = $this->lexer->glimpse(); if ($this->isName('and', $nextToken)) { $this->match(Tokens::T_SP); $this->match(Tokens::T_NAME); $this->match(Tokens::T_SP); $factors[] = $this->factor(); + } else { + $isNextTokenAnd = false; } } diff --git a/tests/ParserFilterModeTest.php b/tests/ParserFilterModeTest.php index 61a453d..ccdc31a 100644 --- a/tests/ParserFilterModeTest.php +++ b/tests/ParserFilterModeTest.php @@ -253,6 +253,60 @@ public function parser_provider_v2() ] ] ], + [ + 'emails co "example.com" and emails.value co "example.org" and emails.value co "example.info"', + [ + 'Conjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + ] + ] + ], + [ + 'emails co "example.com" or emails.value co "example.org" or emails.value co "example.info"', + [ + 'Disjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + ] + ] + ], + [ + 'emails co "example.com" or emails.value co "example.org" or emails.value co "example.info" or (emails co "example.com" and emails.value co "example.org" and emails.value co "example.info")', + [ + 'Disjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + [ + 'Conjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + ] + ] + ] + ] + ], + [ + 'emails co "example.com" or emails.value co "example.org" or emails.value co "example.info" or emails co "example.com" and emails.value co "example.org" and emails.value co "example.info"', + [ + 'Disjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + [ + 'Conjunction' => [ + ['ComparisonExpression' => 'emails co example.com'], + ['ComparisonExpression' => 'emails.value co example.org'], + ['ComparisonExpression' => 'emails.value co example.info'], + ] + ] + ] + ] + ], ]; } From 4ce3dcec1cfcc42eee403e52d6df81288fa3f7f3 Mon Sep 17 00:00:00 2001 From: Andrei Gorgan Date: Fri, 24 Apr 2020 16:49:36 +0300 Subject: [PATCH 7/7] removed changes not concerning this pull request --- src/Ast/ValuePath.php | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Ast/ValuePath.php b/src/Ast/ValuePath.php index c058d78..d708316 100644 --- a/src/Ast/ValuePath.php +++ b/src/Ast/ValuePath.php @@ -29,33 +29,17 @@ public function __construct(AttributePath $attributePath, Filter $filter) $this->filter = $filter; } - /** - * @return AttributePath - */ - public function getAttributePath() - { - return $this->attributePath; - } - - /** - * @return Filter - */ - public function getFilter() - { - return $this->filter; - } - public function __toString() { - return sprintf('%s[%s]', $this->getAttributePath(), $this->getFilter()); + return sprintf('%s[%s]', $this->attributePath, $this->filter); } public function dump() { return [ 'ValuePath' => [ - $this->getAttributePath()->dump(), - $this->getFilter()->dump(), + $this->attributePath->dump(), + $this->filter->dump(), ], ]; }