Download src/Option/Application/CommandHandlers/CreateOptionCommandHandler.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Option/Application/CommandHandlers/CreateOptionCommandHandler.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Option/Application/CommandHandlers/CreateOptionCommandHandler.php
-
curl -L -o CreateOptionCommandHandler.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Option/Application/CommandHandlers/CreateOptionCommandHandler.php
1.03 kB
| declare(strict_types=1); | |
| namespace Option\Application\CommandHandlers; | |
| use Option\Application\Commands\CreateOptionCommand; | |
| use Option\Domain\Entities\OptionEntity; | |
| use Option\Domain\Events\OptionCreatedEvent; | |
| use Option\Domain\Exceptions\KeyTakenException; | |
| use Option\Domain\Repositories\OptionRepositoryInterface; | |
| use Psr\EventDispatcher\EventDispatcherInterface; | |
| class CreateOptionCommandHandler | |
| { | |
| public function __construct( | |
| private OptionRepositoryInterface $repo, | |
| private EventDispatcherInterface $dispatcher, | |
| ) { | |
| } | |
| /** | |
| * @throws KeyTakenException | |
| */ | |
| public function handle(CreateOptionCommand $cmd): OptionEntity | |
| { | |
| $option = new OptionEntity( | |
| $cmd->key, | |
| $cmd->value, | |
| ); | |
| // Add the option to the repository | |
| $this->repo->add($option); | |
| // Dispatch the option created event | |
| $event = new OptionCreatedEvent($option); | |
| $this->dispatcher->dispatch($event); | |
| return $option; | |
| } | |
| } | |