mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-16 16:17:43 +03:00
0d7b8c2b7a
This also includes heavy use of slevomat/coding-standard to apply various checks to the code, based on maintainer (me) preference.
36 lines
943 B
PHP
36 lines
943 B
PHP
<?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;
|
|
|
|
/**
|
|
* Validator validates strings as UUIDs of any variant
|
|
*/
|
|
class Validator 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}$';
|
|
|
|
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);
|
|
}
|
|
}
|