1 | <?php |
||
23 | class NewSingleThreadFormHandler extends AbstractFormHandler |
||
24 | { |
||
25 | /** |
||
26 | * A processor instance. |
||
27 | * |
||
28 | * The processor is responsible for processing the valid form model |
||
29 | * |
||
30 | * @var NewThreadFormProcessorInterface |
||
31 | */ |
||
32 | protected $newThreadProcessor; |
||
33 | |||
34 | /** |
||
35 | * The request when the form was valid. |
||
36 | * |
||
37 | * @var Request |
||
38 | */ |
||
39 | protected $request; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param Request $request The request the form will process |
||
45 | * @param NewThreadFormProcessorInterface $processor A new thread form model processor |
||
46 | */ |
||
47 | public function __construct(Request $request, NewThreadFormProcessorInterface $processor) |
||
54 | |||
55 | /** |
||
56 | * Processes the form with the request |
||
57 | * |
||
58 | * @param FormInterface $form A form instance |
||
59 | */ |
||
60 | public function doProcess(FormInterface $form) |
||
72 | |||
73 | /** |
||
74 | * Gets the form data |
||
75 | * |
||
76 | * Helper function to get auto completion |
||
77 | * |
||
78 | * @param FormInterface $form |
||
79 | * |
||
80 | * @return NewThreadInterface |
||
81 | * |
||
82 | * @throws \InvalidArgumentException when form data is not the expected data |
||
83 | */ |
||
84 | protected function getFormData(FormInterface $form) |
||
85 | { |
||
86 | $data = $form->getData(); |
||
87 | |||
88 | if (!$data instanceof NewThreadInterface) { |
||
89 | throw new \InvalidArgumentException('Form data needs to implement NewThreadInterface'); |
||
90 | } |
||
91 | |||
92 | return $data; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Helper function if you need to extend this class. |
||
97 | * |
||
98 | * Here you have your custom form model which implements the NewThreadInterface. |
||
99 | * If you need extra processing of this valid form model you can extend this class and overwrite this function. |
||
100 | * |
||
101 | * An example... |
||
102 | * You want to store the ip address from the client. |
||
103 | * $newThreadFormModel->setIpAddress = $this->request->getClientIp(); * |
||
104 | * |
||
105 | * @param NewThreadInterface $newThreadFormModel |
||
106 | */ |
||
107 | protected function processFormModelExtra(NewThreadInterface $newThreadFormModel) |
||
111 | } |
||
112 |