|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Explicit Architecture POC, |
|
7
|
|
|
* which is created on top of the Symfony Demo application. |
|
8
|
|
|
* |
|
9
|
|
|
* (c) Herberto Graça <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
12
|
|
|
* file that was distributed with this source code. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Acme\App\Presentation\Web\Infrastructure\Form\Symfony; |
|
16
|
|
|
|
|
17
|
|
|
use Acme\App\Presentation\Web\Core\Port\Form\FormInterface; |
|
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
19
|
|
|
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; |
|
20
|
|
|
use Symfony\Component\Form\Form as SymfonyForm; |
|
21
|
|
|
use Symfony\Component\Form\FormView; |
|
22
|
|
|
|
|
23
|
|
|
final class Form implements FormInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var SymfonyForm |
|
27
|
|
|
*/ |
|
28
|
|
|
private $symfonyForm; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var HttpFoundationFactoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $symfonyResponseFactory; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
HttpFoundationFactoryInterface $symfonyResponseFactory, |
|
37
|
|
|
SymfonyForm $symfonyForm |
|
38
|
|
|
) { |
|
39
|
|
|
$this->symfonyForm = $symfonyForm; |
|
40
|
|
|
$this->symfonyResponseFactory = $symfonyResponseFactory; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function createView(): FormView |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->symfonyForm->createView(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getData() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->symfonyForm->getData(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function handleRequest(ServerRequestInterface $request): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->symfonyForm->handleRequest($this->symfonyResponseFactory->createRequest($request)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function shouldBeProcessed(): bool |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->symfonyForm->isSubmitted() && $this->symfonyForm->isValid(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function clickedButton(string $buttonName): bool |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->symfonyForm->has($buttonName) |
|
66
|
|
|
? $this->symfonyForm->get($buttonName)->isClicked() |
|
|
|
|
|
|
67
|
|
|
: false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getFormName(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->symfonyForm->getName(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
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.