Skip to content

Commit 248184b

Browse files
thomasbisignaninorberttech
authored andcommitted
Added UUID pattern support for the TextMatcher (#130)
* Added UUID pattern support for the TextMatcher * Updated UuidMatcher constants
1 parent a737f22 commit 248184b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Matcher/Pattern/RegexConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Coduo\PHPMatcher\Matcher\Pattern;
66

77
use Coduo\PHPMatcher\Exception\UnknownTypeException;
8+
use Coduo\PHPMatcher\Matcher\UuidMatcher;
89

910
final class RegexConverter
1011
{
@@ -21,6 +22,8 @@ public function toRegex(TypePattern $typePattern) : string
2122
return '(\\-?[0-9]*)';
2223
case 'double':
2324
return '(\\-?[0-9]*[\\.|\\,][0-9]*)';
25+
case 'uuid':
26+
return '('.UuidMatcher::UUID_PATTERN.')';
2427
default:
2528
throw new UnknownTypeException($typePattern->getType());
2629
}

src/Matcher/UuidMatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
final class UuidMatcher extends Matcher
1111
{
1212
const PATTERN = 'uuid';
13-
const UUID_FORMAT_PATTERN = '|^[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$|';
13+
const UUID_PATTERN = '[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}';
14+
const UUID_FORMAT_PATTERN = '|^'.self::UUID_PATTERN.'$|';
1415

1516
private $parser;
1617

tests/Matcher/TextMatcherTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public function matchingData()
107107
'/users/12345/active',
108108
'/users/@[email protected](0)/active',
109109
true
110+
],
111+
[
112+
'/user/ebd1fb0e-45ae-11e8-842f-0ed5f89f718b/profile',
113+
'/user/@uuid@/@string@',
114+
true
115+
],
116+
[
117+
'/user/12345/profile',
118+
'/user/@uuid@/@string@',
119+
false
110120
]
111121
];
112122
}

0 commit comments

Comments
 (0)