Browse Source

quite and dirty class for the Deegraph UUID format

dev
Cerys 3 weeks ago
parent
commit
a407eda42e
  1. 24
      src/DataStructures/UUID.php
  2. 17
      src/Exceptions/InvalidUUIDFormatException.php

24
src/DataStructures/UUID.php

@ -0,0 +1,24 @@
<?php
namespace Darksparrow\DeegraphInteractions\DataStructures;
use Darksparrow\DeegraphInteractions\Exceptions\InvalidUUIDFormatException;
use Exception;
class UUID
{
private string $UUID;
public static string $ValidationRegex = "/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/";
public function __construct(string $uuid)
{
if (preg_match(self::$ValidationRegex, $uuid)) {
$this->UUID = $uuid;
} else {
throw new InvalidUUIDFormatException();
}
}
public function __toString(): string
{
return "{{$this->UUID}}";
}
}

17
src/Exceptions/InvalidUUIDFormatException.php

@ -0,0 +1,17 @@
<?php
namespace Darksparrow\DeegraphInteractions\Exceptions;
use Exception;
class InvalidUUIDFormatException extends Exception
{
public function __construct(
string $message = "The UUID you have given is not a valid UUID format.",
int $code = 422
) {
parent::__construct($message, $code);
$this->message = "$message";
$this->code = $code;
}
}
Loading…
Cancel
Save