feat(shared): add security interfaces, user details contracts and UUID helper
This commit is contained in:
parent
5c10d51fba
commit
909f7abaa4
8 changed files with 90 additions and 0 deletions
9
src/Shared/DDD/Exception/NotFoundException.php
Normal file
9
src/Shared/DDD/Exception/NotFoundException.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shared\DDD\Exception;
|
||||
|
||||
class NotFoundException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
9
src/Shared/DDD/Exception/SecurityException.php
Normal file
9
src/Shared/DDD/Exception/SecurityException.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shared\DDD\Exception;
|
||||
|
||||
class SecurityException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
16
src/Shared/DDD/Security/UserDetails.php
Normal file
16
src/Shared/DDD/Security/UserDetails.php
Normal 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;
|
||||
}
|
||||
10
src/Shared/DDD/Security/UserDetailsProvider.php
Normal file
10
src/Shared/DDD/Security/UserDetailsProvider.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shared\DDD\Security;
|
||||
|
||||
interface UserDetailsProvider
|
||||
{
|
||||
public function currentUser(): ?UserDetails;
|
||||
}
|
||||
12
src/Shared/DDD/Security/UserIdentifier.php
Normal file
12
src/Shared/DDD/Security/UserIdentifier.php
Normal 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;
|
||||
}
|
||||
12
src/Shared/DDD/Security/UserType.php
Normal file
12
src/Shared/DDD/Security/UserType.php
Normal 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;
|
||||
}
|
||||
13
src/Shared/Helpers/Exceptions/InvalidUuidException.php
Normal file
13
src/Shared/Helpers/Exceptions/InvalidUuidException.php
Normal 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}");
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue