30 lines
708 B
PHP
30 lines
708 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Infrastructure\Adapters\Services;
|
|
|
|
use Domain\Models\ValueObjects\SessionId;
|
|
use Domain\Ports\Services\SessionService;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class AppSessionService implements SessionService
|
|
{
|
|
public function __construct(
|
|
private readonly string $sessionKey
|
|
) {
|
|
}
|
|
|
|
public function get(): SessionId
|
|
{
|
|
if (! Session::has($this->sessionKey)) {
|
|
Session::put($this->sessionKey, Uuid::uuid7()->toString());
|
|
}
|
|
|
|
/** @var string $uuidString */
|
|
$uuidString = Session::get($this->sessionKey);
|
|
|
|
return new SessionId(Uuid::fromString($uuidString));
|
|
}
|
|
}
|