1 | <?php |
||
26 | class Form |
||
27 | { |
||
28 | /** |
||
29 | * @var FormFactory |
||
30 | */ |
||
31 | private $formFactory; |
||
32 | |||
33 | /** |
||
34 | * @var DocumentType |
||
35 | */ |
||
36 | private $formType; |
||
37 | |||
38 | /** |
||
39 | * @var ValidatorInterface |
||
40 | */ |
||
41 | private $validator; |
||
42 | |||
43 | /** |
||
44 | * @param FormFactory $formFactory Factory, providing different file document instances. |
||
45 | * @param DocumentType $formType Type of form to be set |
||
46 | * @param ValidatorInterface $validator Validator to verify correctness of the provided data |
||
47 | */ |
||
48 | public function __construct( |
||
49 | FormFactory $formFactory, |
||
50 | DocumentType $formType, |
||
51 | ValidatorInterface $validator |
||
52 | ) { |
||
53 | $this->formFactory = $formFactory; |
||
54 | $this->formType = $formType; |
||
55 | $this->validator = $validator; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param Request $request request |
||
60 | * @param DocumentModel $model model |
||
61 | * |
||
62 | * @return \Symfony\Component\Form\Form |
||
63 | */ |
||
64 | public function getForm(Request $request, DocumentModel $model) |
||
65 | { |
||
66 | $this->formType->initialize($model->getEntityClass()); |
||
67 | return $this->formFactory->create($this->formType, null, ['method' => $request->getMethod()]); |
||
|
|||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Validates the provided information against a form. |
||
72 | * |
||
73 | * @param FormInterface $form form to check |
||
74 | * @param DocumentModel $model Model to determine entity to be used |
||
75 | * @param FormDataMapperInterface $formDataMapper Mapps the entity to form fields |
||
76 | * @param string $jsonContent json data |
||
77 | * |
||
78 | * @throws ValidationException |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function checkForm( |
||
82 | FormInterface $form, |
||
83 | DocumentModel $model, |
||
84 | FormDataMapperInterface $formDataMapper, |
||
85 | $jsonContent |
||
86 | ) { |
||
87 | $document = $formDataMapper->convertToFormData( |
||
88 | $jsonContent, |
||
89 | $model->getEntityClass() |
||
90 | ); |
||
91 | $form->submit($document, true); |
||
92 | |||
93 | if (!$form->isValid()) { |
||
94 | throw new ValidationException($form->getErrors(true)); |
||
95 | } else { |
||
96 | $record = $form->getData(); |
||
97 | } |
||
98 | |||
99 | return $record; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * validate raw json input |
||
104 | * |
||
105 | * @param Request $request request |
||
106 | * @param Response $response response |
||
107 | * @param string $content Alternative request content. |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | public function checkJsonRequest(Request $request, Response $response, $content = '') |
||
150 | |||
151 | /** |
||
152 | * Validate JSON patch for any object |
||
153 | * |
||
154 | * @param array $jsonPatch json patch as array |
||
155 | * |
||
156 | * @throws InvalidJsonPatchException |
||
157 | * @return void |
||
158 | */ |
||
159 | public function checkJsonPatchRequest(array $jsonPatch) |
||
170 | /** |
||
171 | * Used for backwards compatibility to PHP 5.4 |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | private function getLastJsonErrorMessage() |
||
185 | } |
||
186 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: