2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure\Adapters\Services;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\SessionId;
|
|
|
|
|
use Domain\Ports\Services\SessionService;
|
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2026-11-17 12:15:34 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
class AppSessionService implements SessionService
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly string $sessionKey
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get(): SessionId
|
|
|
|
|
{
|
|
|
|
|
if (! Session::has($this->sessionKey)) {
|
2026-11-17 12:15:34 +01:00
|
|
|
Session::put($this->sessionKey, UuidHelper::v7()->toString());
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @var string $uuidString */
|
|
|
|
|
$uuidString = Session::get($this->sessionKey);
|
|
|
|
|
|
2026-11-17 12:15:34 +01:00
|
|
|
return new SessionId(UuidHelper::fromString($uuidString));
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|