mirror of
https://gitlab.com/izyim/prototypes/ddd-example.git
synced 2026-08-19 12:34:08 +00:00
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Src\Zone\User\Application\UseCases\Commands;
|
|
|
|
use Src\Zone\User\Domain\Model\User;
|
|
use Src\Zone\User\Domain\Model\ValueObjects\Password;
|
|
use Src\Zone\User\Domain\Policies\UserPolicy;
|
|
use Src\Zone\User\Domain\Repositories\AvatarRepositoryInterface;
|
|
use Src\Zone\User\Domain\Repositories\UserRepositoryInterface;
|
|
use Src\Common\Domain\CommandInterface;
|
|
|
|
class UpdateUserCommand implements CommandInterface
|
|
{
|
|
private UserRepositoryInterface $repository;
|
|
private AvatarRepositoryInterface $avatarRepository;
|
|
private UserPolicy $policy;
|
|
|
|
public function __construct(
|
|
private readonly User $user,
|
|
private readonly Password $password
|
|
)
|
|
{
|
|
$this->repository = app()->make(UserRepositoryInterface::class);
|
|
$this->avatarRepository = app()->make(AvatarRepositoryInterface::class);
|
|
$this->policy = new UserPolicy();
|
|
}
|
|
|
|
public function execute(): void
|
|
{
|
|
authorize('update', $this->policy, ['user' => $this->user]);
|
|
// if (UserEloquentModel::query()->where('email', $this->user->email)->exists()) {
|
|
// throw new EmailAlreadyUsedException();
|
|
// }
|
|
|
|
$avatar = $this->user->avatar;
|
|
if ($avatar->isBinaryFile()) {
|
|
$filename = $this->avatarRepository->storeAvatarFile($avatar, $this->user->name);
|
|
$this->user->setAvatar($filename);
|
|
}
|
|
|
|
$this->repository->update($this->user, $this->password);
|
|
}
|
|
} |