forked from CodelyTV/php-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiController.php
More file actions
38 lines (31 loc) · 1.02 KB
/
Copy pathApiController.php
File metadata and controls
38 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace CodelyTv\Shared\Infrastructure\Symfony;
use CodelyTv\Shared\Domain\Bus\Command\Command;
use CodelyTv\Shared\Domain\Bus\Command\CommandBus;
use CodelyTv\Shared\Domain\Bus\Query\Query;
use CodelyTv\Shared\Domain\Bus\Query\QueryBus;
use CodelyTv\Shared\Domain\Bus\Query\Response;
use function Lambdish\Phunctional\each;
abstract class ApiController
{
public function __construct(
private readonly QueryBus $queryBus,
private readonly CommandBus $commandBus,
ApiExceptionsHttpStatusCodeMapping $exceptionHandler
) {
each(
fn (int $httpCode, string $exceptionClass) => $exceptionHandler->register($exceptionClass, $httpCode),
$this->exceptions()
);
}
abstract protected function exceptions(): array;
protected function ask(Query $query): ?Response
{
return $this->queryBus->ask($query);
}
protected function dispatch(Command $command): void
{
$this->commandBus->dispatch($command);
}
}