|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Lukasz D. Tulikowski <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace App\Traits; |
|
13
|
|
|
|
|
14
|
|
|
use App\Form\Handler\DefaultFormHandler; |
|
15
|
|
|
use App\Service\Generic\ResponseCreator; |
|
16
|
|
|
use App\Service\Generic\SerializationService; |
|
17
|
|
|
use Doctrine\Common\Inflector\Inflector; |
|
18
|
|
|
use JMS\Serializer\Serializer; |
|
19
|
|
|
use JMS\Serializer\SerializerInterface; |
|
20
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
21
|
|
|
|
|
22
|
|
|
trait ControllerTrait |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var Inflector |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $inflector; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var FormFactoryInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $formFactory; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var DefaultFormHandler |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $formHandler; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ResponseCreator |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $responseCreator; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Serializer |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $serializer; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var SerializationService |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $serializationService; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @required |
|
56
|
|
|
* |
|
57
|
|
|
* @param Inflector $inflector |
|
58
|
|
|
*/ |
|
59
|
51 |
|
public function setInflector(Inflector $inflector): void |
|
60
|
|
|
{ |
|
61
|
51 |
|
$this->inflector = $inflector; |
|
62
|
51 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @required |
|
66
|
|
|
* |
|
67
|
|
|
* @param FormFactoryInterface $formFactory |
|
68
|
|
|
*/ |
|
69
|
51 |
|
public function setFormFactory(FormFactoryInterface $formFactory): void |
|
70
|
|
|
{ |
|
71
|
51 |
|
$this->formFactory = $formFactory; |
|
72
|
51 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @required |
|
76
|
|
|
* |
|
77
|
|
|
* @param DefaultFormHandler $formHandler |
|
78
|
|
|
*/ |
|
79
|
51 |
|
public function setFormHandler(DefaultFormHandler $formHandler): void |
|
80
|
|
|
{ |
|
81
|
51 |
|
$this->formHandler = $formHandler; |
|
82
|
51 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @required |
|
86
|
|
|
* |
|
87
|
|
|
* @param ResponseCreator $responseCreator |
|
88
|
|
|
*/ |
|
89
|
51 |
|
public function setResponseCreator(ResponseCreator $responseCreator): void |
|
90
|
|
|
{ |
|
91
|
51 |
|
$this->responseCreator = $responseCreator; |
|
92
|
51 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @required |
|
96
|
|
|
* |
|
97
|
|
|
* @param SerializerInterface $serializer |
|
98
|
|
|
*/ |
|
99
|
51 |
|
public function setSerializer(SerializerInterface $serializer): void |
|
100
|
|
|
{ |
|
101
|
51 |
|
if (!$serializer instanceof Serializer) { |
|
102
|
|
|
throw new \InvalidArgumentException( |
|
103
|
|
|
sprintf( |
|
104
|
|
|
'Serializer must be instance of %s but %s given', |
|
105
|
|
|
Serializer::class, |
|
106
|
|
|
\get_class($this->serializer) |
|
107
|
|
|
) |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
51 |
|
$this->serializer = $serializer; |
|
112
|
51 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @required |
|
116
|
|
|
* |
|
117
|
|
|
* @param SerializationService $serializationService |
|
118
|
|
|
*/ |
|
119
|
51 |
|
public function setSerializationService(SerializationService $serializationService): void |
|
120
|
|
|
{ |
|
121
|
51 |
|
$this->serializationService = $serializationService; |
|
122
|
51 |
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|