SessionUuid.php
- Pfad:
src/Domain/ValueObject/SessionUuid.php - Namespace: Domain\ValueObject
- Zeilen: 75 | Größe: 1,614 Bytes
- Geändert: 2025-12-25 09:52:03 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 1
- use InvalidArgumentException
Klassen 1
-
SessionUuidclass Zeile 11
Funktionen 7
-
__construct()private Zeile 17 -
fromString()public Zeile 27 -
generate()Zeile 41 -
isValid()Zeile 55 -
value()Zeile 60 -
__toString()Zeile 65 -
equals()Zeile 70
Verwendet von 3
- ChatSession.php constructor
- ChatSession.php use
- ChatSessionFactory.php use
Code
<?php
declare(strict_types=1);
namespace Domain\ValueObject;
// @responsibility: Immutables Value Object für Chat-Session-UUID
use InvalidArgumentException;
final class SessionUuid
{
private const UUID_PATTERN = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
private string $value;
private function __construct(string $value)
{
$this->value = $value;
}
/**
* Create from existing UUID string.
*
* @throws InvalidArgumentException
*/
public static function fromString(string $uuid): self
{
$uuid = strtolower(trim($uuid));
if (!self::isValid($uuid)) {
throw new InvalidArgumentException("Invalid UUID v4 format: {$uuid}");
}
return new self($uuid);
}
/**
* Generate a new UUID v4.
*/
public static function generate(): self
{
$data = random_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
$uuid = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
return new self($uuid);
}
/**
* Check if a string is a valid UUID v4.
*/
public static function isValid(string $uuid): bool
{
return preg_match(self::UUID_PATTERN, $uuid) === 1;
}
public function value(): string
{
return $this->value;
}
public function __toString(): string
{
return $this->value;
}
public function equals(self $other): bool
{
return $this->value === $other->value;
}
}