class GenericValidator
GenericValidator validates strings as UUIDs of any variant
@psalm-immutable
Hierarchy
- class \Ramsey\Uuid\Validator\GenericValidator implements \Ramsey\Uuid\Validator\ValidatorInterface
Expanded class hierarchy of GenericValidator
1 file declares its use of GenericValidator
- FeatureSet.php in vendor/
ramsey/ uuid/ src/ FeatureSet.php
File
-
vendor/
ramsey/ uuid/ src/ Validator/ GenericValidator.php, line 27
Namespace
Ramsey\Uuid\ValidatorView source
final class GenericValidator implements ValidatorInterface {
/**
* Regular expression pattern for matching a UUID of any variant.
*/
private const VALID_PATTERN = '\\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\z';
/**
* @psalm-return non-empty-string
* @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty
* @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty
*/
public function getPattern() : string {
return self::VALID_PATTERN;
}
public function validate(string $uuid) : bool {
$uuid = str_replace([
'urn:',
'uuid:',
'URN:',
'UUID:',
'{',
'}',
], '', $uuid);
return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
GenericValidator::getPattern | public | function | @psalm-return non-empty-string @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty |
Overrides ValidatorInterface::getPattern |
GenericValidator::validate | public | function | Returns true if the provided string represents a UUID | Overrides ValidatorInterface::validate |
GenericValidator::VALID_PATTERN | private | constant | Regular expression pattern for matching a UUID of any variant. |