inklabs/kommerce-core

View on GitHub
src/ActionHandler/Attachment/CreateAttachmentForOrderItemHandler.php

Summary

Maintainability
A
1 hr
Test Coverage
<?php
namespace inklabs\kommerce\ActionHandler\Attachment;

use inklabs\kommerce\Action\Attachment\CreateAttachmentForOrderItemCommand;
use inklabs\kommerce\Lib\Authorization\AuthorizationContextInterface;
use inklabs\kommerce\Lib\Command\CommandHandlerInterface;
use inklabs\kommerce\Service\AttachmentServiceInterface;

final class CreateAttachmentForOrderItemHandler implements CommandHandlerInterface
{
    /** @var CreateAttachmentForOrderItemCommand */
    private $command;

    /** @var AttachmentServiceInterface */
    private $attachmentService;

    public function __construct(
        CreateAttachmentForOrderItemCommand $command,
        AttachmentServiceInterface $attachmentService
    ) {
        $this->command = $command;
        $this->attachmentService = $attachmentService;
    }

    public function verifyAuthorization(AuthorizationContextInterface $authorizationContext): void
    {
        $authorizationContext->verifyIsAdmin();
    }

    public function handle()
    {
        $this->attachmentService->createAttachmentForOrderItem(
            $this->command->getUploadFileDTO(),
            $this->command->getOrderItemId()
        );
    }
}