mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Add ValidatorInterface::getPattern() and set constants to private
This commit is contained in:
@@ -23,14 +23,22 @@ use function str_replace;
|
||||
/**
|
||||
* Rfc4122\Validator validates strings as UUIDs of the RFC 4122 variant
|
||||
*/
|
||||
class Validator implements ValidatorInterface
|
||||
final class Validator implements ValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Regular expression pattern for matching an RFC 4122 UUID
|
||||
*/
|
||||
public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
|
||||
private const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
|
||||
. '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$';
|
||||
|
||||
/**
|
||||
* @psalm-pure
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-pure
|
||||
*/
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ class Uuid implements UuidInterface
|
||||
public const RESERVED_FUTURE = 7;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@see GenericValidator::VALID_PATTERN} instead.
|
||||
* @deprecated Use {@see ValidatorInterface::getPattern()} instead.
|
||||
*/
|
||||
public const VALID_PATTERN = '^[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}$';
|
||||
|
||||
|
||||
@@ -22,12 +22,23 @@ use function str_replace;
|
||||
/**
|
||||
* GenericValidator validates strings as UUIDs of any variant
|
||||
*/
|
||||
class GenericValidator implements ValidatorInterface
|
||||
final class GenericValidator implements ValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Regular expression pattern for matching a UUID of any variant.
|
||||
*/
|
||||
public const VALID_PATTERN = '^[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}$';
|
||||
private const VALID_PATTERN = '^[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}$';
|
||||
|
||||
/**
|
||||
* @psalm-pure
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-pure
|
||||
|
||||
@@ -19,6 +19,16 @@ namespace Ramsey\Uuid\Validator;
|
||||
*/
|
||||
interface ValidatorInterface
|
||||
{
|
||||
/**
|
||||
* Returns the regular expression pattern used by this validator
|
||||
*
|
||||
* @return string The regular expression pattern this validator uses
|
||||
*
|
||||
* @psalm-pure
|
||||
* @psalm-return non-empty-string
|
||||
*/
|
||||
public function getPattern(): string;
|
||||
|
||||
/**
|
||||
* Returns true if the provided string represents a UUID
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user