src/ActionHandler/Tag/GetTagsByIdsHandler.php
<?php
namespace inklabs\kommerce\ActionHandler\Tag;
use inklabs\kommerce\Action\Tag\GetTagsByIdsQuery;
use inklabs\kommerce\ActionResponse\Tag\GetTagsByIdsResponse;
use inklabs\kommerce\EntityDTO\Builder\DTOBuilderFactoryInterface;
use inklabs\kommerce\EntityRepository\TagRepositoryInterface;
use inklabs\kommerce\Lib\Authorization\AuthorizationContextInterface;
use inklabs\kommerce\Lib\Query\QueryHandlerInterface;
final class GetTagsByIdsHandler implements QueryHandlerInterface
{
/** @var GetTagsByIdsQuery */
private $query;
/** @var TagRepositoryInterface */
private $tagRepository;
/** @var DTOBuilderFactoryInterface */
private $dtoBuilderFactory;
public function __construct(
GetTagsByIdsQuery $query,
TagRepositoryInterface $tagRepository,
DTOBuilderFactoryInterface $dtoBuilderFactory
) {
$this->query = $query;
$this->tagRepository = $tagRepository;
$this->dtoBuilderFactory = $dtoBuilderFactory;
}
public function verifyAuthorization(AuthorizationContextInterface $authorizationContext): void
{
$authorizationContext->verifyCanMakeRequests();
}
public function handle()
{
$response = new GetTagsByIdsResponse();
$tags = $this->tagRepository->getTagsByIds(
$this->query->getTagIds()
);
foreach ($tags as $tag) {
$response->addTagDTOBuilder(
$this->dtoBuilderFactory->getTagDTOBuilder($tag)
);
}
return $response;
}
}