1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BitBag\SyliusWishlistPlugin\Controller\Action; |
6
|
|
|
|
7
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\ImportWishlistFromCsv; |
8
|
|
|
use BitBag\SyliusWishlistPlugin\Form\Type\ImportWishlistFromCsvType; |
9
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
10
|
|
|
use Symfony\Component\Form\FormInterface; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
14
|
|
|
use Symfony\Component\Messenger\HandleTrait; |
15
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
16
|
|
|
use Twig\Environment; |
17
|
|
|
|
18
|
|
|
final class ImportWishlistFromCsvAction |
19
|
|
|
{ |
20
|
|
|
use HandleTrait; |
21
|
|
|
|
22
|
|
|
private FormFactoryInterface $formFactory; |
23
|
|
|
|
24
|
|
|
private FlashBagInterface $flashBag; |
25
|
|
|
|
26
|
|
|
private Environment $twigEnvironment; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
FormFactoryInterface $formFactory, |
30
|
|
|
FlashBagInterface $flashBag, |
31
|
|
|
MessageBusInterface $messageBus, |
32
|
|
|
Environment $twigEnvironment |
33
|
|
|
) { |
34
|
|
|
$this->formFactory = $formFactory; |
35
|
|
|
$this->flashBag = $flashBag; |
36
|
|
|
$this->messageBus = $messageBus; |
37
|
|
|
$this->twigEnvironment = $twigEnvironment; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function __invoke(Request $request): Response |
41
|
|
|
{ |
42
|
|
|
$form = $this->createForm(); |
43
|
|
|
|
44
|
|
|
$form->handleRequest($request); |
45
|
|
|
|
46
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
47
|
|
|
return $this->handleCommand($form, $request); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
foreach ($form->getErrors() as $error) { |
51
|
|
|
$this->flashBag->add('error', $error->getMessage()); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new Response( |
55
|
|
|
$this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/importWishlist.html.twig', [ |
56
|
|
|
'form' => $form->createView(), |
57
|
|
|
]) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function createForm(): FormInterface |
62
|
|
|
{ |
63
|
|
|
return $this->formFactory->create(ImportWishlistFromCsvType::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function handleCommand(FormInterface $form, Request $request): Response |
67
|
|
|
{ |
68
|
|
|
$file = $form->get('wishlist_file')->getData(); |
69
|
|
|
$command = new ImportWishlistFromCsv($file->getFileInfo(), $request); |
70
|
|
|
|
71
|
|
|
return $this->handle($command); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.