-
-
Notifications
You must be signed in to change notification settings - Fork 86
Allow to mark JSON properties & XML nodes as optional #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4c78197
Add optional expander definition
teklakct d6ec56c
Add hasExpander method for Pattern
teklakct ff9ab1a
Allow mark JSON properties & xml nodes as optional
teklakct ef29d68
Use intuitive matcher type definition in Xml test stock qty node defi…
teklakct b780687
Add information about optional Expander to README
teklakct 3de0aab
Remove return type declaration
teklakct c8e0045
Catch PHPMatcher Exception when parsing pattern for optional values
teklakct 12c60ce
Add getName to PatternExpander interface
teklakct a454c90
Remove unncessary ExpanderInitializer dependency in TypePattern
teklakct 1df7251
Use constants for expander name instead of method
teklakct a50d669
Redeclare $expanderDefinitions using constants
teklakct 1088d4f
Add static is($name) method to PatternExpander interface
teklakct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ $matcher->getError(); // returns null or error message | |
* ``inArray($value)`` | ||
* ``oneOf(...$expanders)`` - example usage ``"@[email protected](contains('foo'), contains('bar'), contains('baz'))"`` | ||
* ``matchRegex($regex)`` - example usage ``"@[email protected]('/^lorem.+/')"`` | ||
* ``optional()`` - work's only with ``ArrayMatcher``, ``JsonMatcher`` and ``XmlMatcher`` | ||
|
||
##Example usage | ||
|
||
|
@@ -237,7 +238,8 @@ $matcher->match( | |
'id' => 1, | ||
'firstName' => 'Norbert', | ||
'lastName' => 'Orzechowicz', | ||
'roles' => array('ROLE_USER') | ||
'roles' => array('ROLE_USER'), | ||
'position' => 'Developer', | ||
), | ||
array( | ||
'id' => 2, | ||
|
@@ -261,7 +263,8 @@ $matcher->match( | |
'id' => '@[email protected](0)', | ||
'firstName' => '@string@', | ||
'lastName' => 'Orzechowicz', | ||
'roles' => '@array@' | ||
'roles' => '@array@', | ||
'position' => '@[email protected]()' | ||
), | ||
array( | ||
'id' => '@integer@', | ||
|
@@ -303,7 +306,8 @@ $matcher->match( | |
"firstName": @string@, | ||
"lastName": @string@, | ||
"created": "@[email protected]()", | ||
"roles": @array@ | ||
"roles": @array@, | ||
"posiiton": "@[email protected]()" | ||
} | ||
] | ||
}' | ||
|
@@ -347,6 +351,7 @@ XML | |
<m:GetStockPrice> | ||
<m:StockName>@string@</m:StockName> | ||
<m:StockValue>@string@</m:StockValue> | ||
<m:StockQty>@[email protected]()</m:StockQty> | ||
</m:GetStockPrice> | ||
</soap:Body> | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class Contains implements PatternExpander | ||
{ | ||
const NAME = 'contains'; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class Count implements PatternExpander | ||
{ | ||
const NAME = 'count'; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class EndsWith implements PatternExpander | ||
{ | ||
const NAME = 'endsWith'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class GreaterThan implements PatternExpander | ||
{ | ||
const NAME = 'greaterThan'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class InArray implements PatternExpander | ||
{ | ||
const NAME = 'inArray'; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class IsEmail implements PatternExpander | ||
{ | ||
const NAME = 'isEmail'; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class IsEmpty implements PatternExpander | ||
{ | ||
const NAME = 'isEmpty'; | ||
|
||
private $error; | ||
|
||
/** | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class IsNotEmpty implements PatternExpander | ||
{ | ||
const NAME = 'isNotEmpty'; | ||
|
||
private $error; | ||
|
||
/** | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class IsUrl implements PatternExpander | ||
{ | ||
const NAME = 'isUrl'; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class LowerThan implements PatternExpander | ||
{ | ||
const NAME = 'lowerThan'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class OneOf implements PatternExpander | ||
{ | ||
const NAME = 'oneOf'; | ||
|
||
/** | ||
* @var PatternExpander[] | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Coduo\PHPMatcher\Matcher\Pattern\Expander; | ||
|
||
use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; | ||
|
||
final class Optional implements PatternExpander | ||
{ | ||
const NAME = 'optional'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function match($value) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getError() | ||
{ | ||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
final class StartsWith implements PatternExpander | ||
{ | ||
const NAME = 'startsWith'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,10 +69,24 @@ public function matchExpanders($value) | |
} | ||
|
||
/** | ||
* @return null|string | ||
* {@inheritdoc} | ||
*/ | ||
public function getError() | ||
{ | ||
return $this->error; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasExpander(string $expanderName) | ||
{ | ||
foreach ($this->expanders as $expander) { | ||
if ($expander::NAME === $expanderName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's the problem, interface can't guarantee that Expander will have |
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@norzechowicz I'm not pretty sure that we must check if values match to pattern because it already hasn't
array_diff_key($pattern, $values)
and also because OptionalExpander works only with top level match