Rename Validator\Validator to Validator\GenericValidator

This commit is contained in:
Ben Ramsey
2020-01-13 16:08:29 -06:00
parent 2ad77d9ca7
commit 5d1f106882
4 changed files with 9 additions and 9 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
*/
declare(strict_types=1);
namespace Ramsey\Uuid\Validator;
use Ramsey\Uuid\Uuid;
/**
* GenericValidator validates strings as UUIDs of any variant
*/
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}$';
/**
* @psalm-pure
*/
public function validate(string $uuid): bool
{
$uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid);
return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/D', $uuid);
}
}