chore: complete update
This commit is contained in:
52
src/Framework/Http/Session/SessionId.php
Normal file
52
src/Framework/Http/Session/SessionId.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Http\Session;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final readonly class SessionId
|
||||
{
|
||||
private function __construct(private string $value)
|
||||
{
|
||||
$this->validate($value);
|
||||
}
|
||||
|
||||
public static function fromString(string $value): self
|
||||
{
|
||||
return new self($value);
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
public function equals(SessionId $other): bool
|
||||
{
|
||||
return $this->value === $other->value;
|
||||
}
|
||||
|
||||
private function validate(string $value): void
|
||||
{
|
||||
if (empty($value)) {
|
||||
throw new InvalidArgumentException('SessionId darf nicht leer sein');
|
||||
}
|
||||
|
||||
// Weitere Validierungen je nach Anforderungen
|
||||
// z.B. Mindestlänge, erlaubte Zeichen, Format
|
||||
if (strlen($value) < 32) {
|
||||
throw new InvalidArgumentException('SessionId muss mindestens 32 Zeichen lang sein');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value)) {
|
||||
throw new InvalidArgumentException('SessionId darf nur alphanumerische Zeichen enthalten');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user