Cerys
3 weeks ago
2 changed files with 41 additions and 0 deletions
@ -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}}"; |
|||
} |
|||
} |
@ -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…
Reference in new issue