feat(shared): add security interfaces, user details contracts and UUID helper

This commit is contained in:
Jérémy Munsch 2026-08-18 12:03:22 +02:00
parent 5c10d51fba
commit 909f7abaa4
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
8 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Exception;
class NotFoundException extends \RuntimeException
{
}

View file

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Exception;
class SecurityException extends \RuntimeException
{
}

View file

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Security;
interface UserDetails
{
public function id(): string;
public function name(): string;
public function type(): UserType;
public function identifier(): string;
}

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Security;
interface UserDetailsProvider
{
public function currentUser(): ?UserDetails;
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Security;
use Shared\DDD\Model\Equatable;
interface UserIdentifier extends Equatable
{
public function value(): string;
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Shared\DDD\Security;
use Shared\DDD\Model\Equatable;
interface UserType extends Equatable
{
public function type(): string;
}

View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Shared\Helpers\Exceptions;
final class InvalidUuidException extends \InvalidArgumentException
{
public static function forValue(string $uuid): self
{
return new self("Invalid UUID: {$uuid}");
}
}

View file

@ -5,7 +5,9 @@ declare(strict_types=1);
namespace Shared\Helpers;
use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Shared\Helpers\Exceptions\InvalidUuidException;
final readonly class UuidHelper
{
@ -44,4 +46,11 @@ final readonly class UuidHelper
return 0;
}
public static function validateUuid(UuidInterface $uuid): void
{
if (! Uuid::isValid($uuid->toString())) {
throw InvalidUuidException::forValue($uuid->toString());
}
}
}