2023-09-19 14:27:33 +06:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Services\Captcha;
|
|
|
|
|
|
|
|
use App\Dto\HttpUserData;
|
|
|
|
use App\Enums\CaptchaLogType;
|
|
|
|
use App\Models\Captcha;
|
|
|
|
use App\Models\CaptchaToken;
|
|
|
|
use App\Services\CaptchaLog\CaptchaLogHandler;
|
|
|
|
use App\Services\GenerateTokenCommand\GenerateTokenUuidCommand;
|
|
|
|
|
|
|
|
final readonly class CaptchaHandler
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
private GenerateTokenUuidCommand $uuidCommand,
|
|
|
|
private CaptchaLogHandler $captchaLogHandler
|
|
|
|
) { }
|
|
|
|
|
|
|
|
public function handleStore(CaptchaToken $captchaToken, HttpUserData $httpUserData): Captcha
|
|
|
|
{
|
|
|
|
$captcha = $captchaToken->captchas()->create([
|
|
|
|
'uuid' => $this->uuidCommand->unique($captchaToken->captchas()->getQuery(), 'uuid')
|
|
|
|
]);
|
2023-11-26 15:09:42 +06:00
|
|
|
$this->captchaLogHandler->handleStore($captcha->id, CaptchaLogType::Created, $httpUserData);
|
2023-09-19 14:27:33 +06:00
|
|
|
|
|
|
|
return $captcha;
|
|
|
|
}
|
|
|
|
}
|