|
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\FormFactoryInterface; |
|
18
|
|
|
use Acme\App\Presentation\Web\Core\Port\Form\FormInterface; |
|
19
|
|
|
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\CommentForm; |
|
20
|
|
|
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\CreatePostForm; |
|
21
|
|
|
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form\EditPostForm; |
|
22
|
|
|
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; |
|
23
|
|
|
use Symfony\Component\Form\Form as SymfonyForm; |
|
24
|
|
|
use Symfony\Component\Form\FormFactoryInterface as SymfonyFormFactoryInterface; |
|
25
|
|
|
|
|
26
|
|
|
final class FormFactory implements FormFactoryInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var SymfonyFormFactoryInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $symfonyFormFactory; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var HttpFoundationFactoryInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $symfonyResponseFactory; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
HttpFoundationFactoryInterface $symfonyResponseFactory, |
|
40
|
|
|
SymfonyFormFactoryInterface $symfonyFormFactory |
|
41
|
|
|
) { |
|
42
|
|
|
$this->symfonyResponseFactory = $symfonyResponseFactory; |
|
43
|
|
|
$this->symfonyFormFactory = $symfonyFormFactory; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
public function createEditPostForm($data = null, array $options = []): FormInterface |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
/** @var SymfonyForm $form */ |
|
49
|
|
|
$form = $this->symfonyFormFactory->create(EditPostForm::class, $data, $options); |
|
50
|
|
|
|
|
51
|
|
|
return new Form($this->symfonyResponseFactory, $form); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
View Code Duplication |
public function createCreatePostForm($data = null, array $options = []): FormInterface |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
/** @var SymfonyForm $form */ |
|
57
|
|
|
$form = $this->symfonyFormFactory->create(CreatePostForm::class, $data, $options); |
|
58
|
|
|
|
|
59
|
|
|
return new Form($this->symfonyResponseFactory, $form); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
public function createCommentForm($data = null, array $options = []): FormInterface |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
/** @var SymfonyForm $form */ |
|
65
|
|
|
$form = $this->symfonyFormFactory->create(CommentForm::class, $data, $options); |
|
66
|
|
|
|
|
67
|
|
|
return new Form($this->symfonyResponseFactory, $form); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.