From b9812ba06ac16899df2a25f0abf25962ae3273f2 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 30 May 2023 08:36:17 +0000 Subject: update composer libs --- vendor/ramsey/uuid/src/Type/Hexadecimal.php | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'vendor/ramsey/uuid/src/Type/Hexadecimal.php') diff --git a/vendor/ramsey/uuid/src/Type/Hexadecimal.php b/vendor/ramsey/uuid/src/Type/Hexadecimal.php index 3c8f30adf..bf71ec4b1 100644 --- a/vendor/ramsey/uuid/src/Type/Hexadecimal.php +++ b/vendor/ramsey/uuid/src/Type/Hexadecimal.php @@ -17,10 +17,8 @@ namespace Ramsey\Uuid\Type; use Ramsey\Uuid\Exception\InvalidArgumentException; use ValueError; -use function ctype_xdigit; +use function preg_match; use function sprintf; -use function str_starts_with; -use function strtolower; use function substr; /** @@ -37,23 +35,11 @@ final class Hexadecimal implements TypeInterface private string $value; /** - * @param string $value The hexadecimal value to store + * @param self|string $value The hexadecimal value to store */ - public function __construct(string $value) + public function __construct(self | string $value) { - $value = strtolower($value); - - if (str_starts_with($value, '0x')) { - $value = substr($value, 2); - } - - if (!ctype_xdigit($value)) { - throw new InvalidArgumentException( - 'Value must be a hexadecimal number' - ); - } - - $this->value = $value; + $this->value = $value instanceof self ? (string) $value : $this->prepareValue($value); } public function toString(): string @@ -109,4 +95,21 @@ final class Hexadecimal implements TypeInterface $this->unserialize($data['string']); } + + private function prepareValue(string $value): string + { + $value = strtolower($value); + + if (str_starts_with($value, '0x')) { + $value = substr($value, 2); + } + + if (!preg_match('/^[A-Fa-f0-9]+$/', $value)) { + throw new InvalidArgumentException( + 'Value must be a hexadecimal number' + ); + } + + return $value; + } } -- cgit v1.2.3