31 lines
799 B
PHP
31 lines
799 B
PHP
<?php
|
|
|
|
namespace App\User\UseCases\EnsureInitialAdmin;
|
|
|
|
use App\Auth\PasswordHasher;
|
|
use App\Shared\ValueObject\EmailAddress;
|
|
use App\User\CreateUserDto;
|
|
use App\User\UserRepository;
|
|
|
|
class EnsureInitialAdmin
|
|
{
|
|
public function __construct(
|
|
private UserRepository $userRepository,
|
|
private PasswordHasher $passwordHasher,
|
|
) {
|
|
}
|
|
|
|
public function execute(EnsureInitialAdminRequest $request): void
|
|
{
|
|
$email = new EmailAddress($request->email);
|
|
$existingUser = $this->userRepository->findByEmail($email);
|
|
if ($existingUser !== null) {
|
|
return;
|
|
}
|
|
|
|
$this->userRepository->create(new CreateUserDto(
|
|
email: $email,
|
|
passwordHash: $this->passwordHasher->hash($request->password),
|
|
));
|
|
}
|
|
}
|