1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sylius\ShopApiPlugin\Controller\Customer; |
4
|
|
|
|
5
|
|
|
use FOS\RestBundle\View\View; |
6
|
|
|
use FOS\RestBundle\View\ViewHandlerInterface; |
7
|
|
|
use League\Tactician\CommandBus; |
8
|
|
|
use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
9
|
|
|
use Sylius\ShopApiPlugin\Command\PickupCart; |
10
|
|
|
use Sylius\ShopApiPlugin\Factory\ValidationErrorViewFactoryInterface; |
11
|
|
|
use Sylius\ShopApiPlugin\Request\PickupCartRequest; |
12
|
|
|
use Sylius\ShopApiPlugin\Request\ResendVerificationTokenRequest; |
13
|
|
|
use Sylius\ShopApiPlugin\View\ValidationErrorView; |
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
18
|
|
|
use Symfony\Component\Validator\ConstraintViolationInterface; |
19
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
20
|
|
|
|
21
|
|
|
final class ResendVerificationTokenAction |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ViewHandlerInterface |
25
|
|
|
*/ |
26
|
|
|
private $viewHandler; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var CommandBus |
30
|
|
|
*/ |
31
|
|
|
private $bus; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ValidatorInterface |
35
|
|
|
*/ |
36
|
|
|
private $validator; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ValidationErrorViewFactoryInterface |
40
|
|
|
*/ |
41
|
|
|
private $validationErrorViewFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ViewHandlerInterface $viewHandler |
45
|
|
|
* @param CommandBus $bus |
46
|
|
|
* @param ValidatorInterface $validator |
47
|
|
|
* @param ValidationErrorViewFactoryInterface $validationErrorViewFactory |
48
|
|
|
*/ |
49
|
|
|
public function __construct( |
50
|
|
|
ViewHandlerInterface $viewHandler, |
51
|
|
|
CommandBus $bus, |
52
|
|
|
ValidatorInterface $validator, |
53
|
|
|
ValidationErrorViewFactoryInterface $validationErrorViewFactory |
54
|
|
|
) { |
55
|
|
|
$this->viewHandler = $viewHandler; |
56
|
|
|
$this->bus = $bus; |
57
|
|
|
$this->validator = $validator; |
58
|
|
|
$this->validationErrorViewFactory = $validationErrorViewFactory; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param Request $request |
63
|
|
|
* |
64
|
|
|
* @return Response |
65
|
|
|
*/ |
66
|
|
|
public function __invoke(Request $request) |
67
|
|
|
{ |
68
|
|
|
$pickupRequest = new ResendVerificationTokenRequest($request); |
69
|
|
|
|
70
|
|
|
$validationResults = $this->validator->validate($pickupRequest); |
71
|
|
|
|
72
|
|
|
if (0 !== count($validationResults)) { |
73
|
|
|
return $this->viewHandler->handle(View::create($this->validationErrorViewFactory->create($validationResults), Response::HTTP_BAD_REQUEST)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->bus->handle($pickupRequest->getCommand()); |
77
|
|
|
|
78
|
|
|
return $this->viewHandler->handle(View::create(null, Response::HTTP_CREATED)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|