diff --git a/src/Matcher/Pattern/RegexConverter.php b/src/Matcher/Pattern/RegexConverter.php index d405750e..a338287f 100644 --- a/src/Matcher/Pattern/RegexConverter.php +++ b/src/Matcher/Pattern/RegexConverter.php @@ -5,6 +5,7 @@ namespace Coduo\PHPMatcher\Matcher\Pattern; use Coduo\PHPMatcher\Exception\UnknownTypeException; +use Coduo\PHPMatcher\Matcher\UuidMatcher; final class RegexConverter { @@ -21,6 +22,8 @@ public function toRegex(TypePattern $typePattern) : string return '(\\-?[0-9]*)'; case 'double': return '(\\-?[0-9]*[\\.|\\,][0-9]*)'; + case 'uuid': + return '('.UuidMatcher::UUID_PATTERN.')'; default: throw new UnknownTypeException($typePattern->getType()); } diff --git a/src/Matcher/UuidMatcher.php b/src/Matcher/UuidMatcher.php index fdbf082f..fd8a3829 100644 --- a/src/Matcher/UuidMatcher.php +++ b/src/Matcher/UuidMatcher.php @@ -10,7 +10,8 @@ final class UuidMatcher extends Matcher { const PATTERN = 'uuid'; - const UUID_FORMAT_PATTERN = '|^[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$|'; + const UUID_PATTERN = '[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}'; + const UUID_FORMAT_PATTERN = '|^'.self::UUID_PATTERN.'$|'; private $parser; diff --git a/tests/Matcher/TextMatcherTest.php b/tests/Matcher/TextMatcherTest.php index ff2c62ba..3e2458ab 100644 --- a/tests/Matcher/TextMatcherTest.php +++ b/tests/Matcher/TextMatcherTest.php @@ -107,6 +107,16 @@ public function matchingData() '/users/12345/active', '/users/@integer@.greaterThan(0)/active', true + ], + [ + '/user/ebd1fb0e-45ae-11e8-842f-0ed5f89f718b/profile', + '/user/@uuid@/@string@', + true + ], + [ + '/user/12345/profile', + '/user/@uuid@/@string@', + false ] ]; }