33 lines
931 B
PHP
33 lines
931 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Domain\Shared\Application\CommandHandler;
|
|
|
|
use App\Domain\Shared\Application\Command\DeleteJob;
|
|
use App\Domain\Shared\Domain\Contract\CommandHandlerInterface;
|
|
use App\Domain\Shared\Domain\Contract\CommandInterface;
|
|
use App\Domain\Shared\Domain\Contract\JobRepositoryInterface;
|
|
|
|
readonly class DeleteJobHandler implements CommandHandlerInterface
|
|
{
|
|
public function __construct(
|
|
private JobRepositoryInterface $jobRepository
|
|
) {
|
|
}
|
|
|
|
public function handle(CommandInterface $command): void
|
|
{
|
|
if (!$command instanceof DeleteJob) {
|
|
throw new \InvalidArgumentException(sprintf(
|
|
'Command must be instance of %s, %s given',
|
|
DeleteJob::class,
|
|
get_class($command)
|
|
));
|
|
}
|
|
|
|
$this->jobRepository->get($command->id);
|
|
$this->jobRepository->delete($command->id);
|
|
}
|
|
}
|