|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* 2017 Romain CANON <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU General Public License, either |
|
8
|
|
|
* version 3 of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, see: |
|
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Romm\Formz\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use Romm\Formz\Core\Core; |
|
17
|
|
|
use Romm\Formz\Form\FormInterface; |
|
18
|
|
|
use Romm\Formz\Form\FormObjectFactory; |
|
19
|
|
|
use Romm\Formz\Middleware\State\MiddlewareState; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\Argument; |
|
22
|
|
|
use TYPO3\CMS\Extbase\Property\PropertyMapper; |
|
23
|
|
|
use TYPO3\CMS\Extbase\Security\Cryptography\HashService; |
|
24
|
|
|
|
|
25
|
|
|
class FormController extends ActionController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var FormzControllerContext |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $formzControllerContext; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var HashService |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $hashService; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Main action used to dispatch the request properly, depending on FormZ |
|
39
|
|
|
* configuration. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function processFormAction() |
|
42
|
|
|
{ |
|
43
|
|
|
$tt = new \TYPO3\CMS\Core\TimeTracker\TimeTracker(); |
|
44
|
|
|
$tt->start(); |
|
45
|
|
|
|
|
46
|
|
|
$this->dispatchMiddlewares(); |
|
47
|
|
|
|
|
48
|
|
|
$this->formzControllerContext->setDispatched(true); |
|
49
|
|
|
|
|
50
|
|
|
$request = $this->formzControllerContext->getRequest(); |
|
51
|
|
|
|
|
52
|
|
|
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($tt->getDifferenceToStarttime(), 'TIME'); |
|
53
|
|
|
$this->forward( |
|
54
|
|
|
$request->getControllerActionName(), |
|
55
|
|
|
$request->getControllerName(), |
|
56
|
|
|
$request->getControllerExtensionName(), |
|
57
|
|
|
$request->getArguments() |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function dispatchMiddlewares() |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var FormObjectFactory $formObjectFactory */ |
|
64
|
|
|
$formObjectFactory = Core::instantiate(FormObjectFactory::class); |
|
65
|
|
|
|
|
66
|
|
|
/** @var Argument $argument */ |
|
67
|
|
|
foreach ($this->formzControllerContext->getArguments() as $argument) { |
|
68
|
|
|
$type = $argument->getDataType(); |
|
69
|
|
|
|
|
70
|
|
|
if (class_exists($type) |
|
71
|
|
|
&& in_array(FormInterface::class, class_implements($type)) |
|
72
|
|
|
) { |
|
73
|
|
|
$formObject = $formObjectFactory->getInstanceFromClassName($type, $argument->getName()); |
|
74
|
|
|
|
|
75
|
|
|
if (false === $formObject->getConfigurationValidationResult()->hasErrors()) { |
|
76
|
|
|
/** @var MiddlewareState $middlewareFactory */ |
|
77
|
|
|
$middlewareFactory = Core::instantiate(MiddlewareState::class, $formObject, $this->formzControllerContext); |
|
78
|
|
|
|
|
79
|
|
|
$middlewareFactory->run(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function aze() |
|
86
|
|
|
{ |
|
87
|
|
|
$arguments = $this->formzControllerContext->getArguments(); |
|
88
|
|
|
|
|
89
|
|
|
foreach ($arguments as $argument) { |
|
90
|
|
|
/** @var Argument $argument */ |
|
91
|
|
|
if ($this->request->hasArgument($argument->getName()) |
|
92
|
|
|
&& true === class_exists($argument->getDataType()) |
|
93
|
|
|
&& true === in_array(FormInterface::class, class_implements($argument->getDataType())) |
|
94
|
|
|
) { |
|
95
|
|
|
/** @var PropertyMapper $propertyMapper */ |
|
96
|
|
|
$propertyMapper = Core::instantiate(PropertyMapper::class); |
|
97
|
|
|
$form = $propertyMapper->convert( |
|
98
|
|
|
$this->request->getArgument($argument->getName()), |
|
99
|
|
|
$argument->getDataType() |
|
100
|
|
|
); |
|
101
|
|
|
break; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $form; |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @todo |
|
110
|
|
|
* |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function getRequestData() |
|
114
|
|
|
{ |
|
115
|
|
|
$requestData = []; |
|
116
|
|
|
|
|
117
|
|
|
if ($this->request->hasArgument('formz')) { |
|
118
|
|
|
$requestData = $this->request->getArgument('formz'); |
|
119
|
|
|
$requestData = $this->hashService->validateAndStripHmac($requestData); |
|
120
|
|
|
$requestData = unserialize(base64_decode($requestData)); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $requestData; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param FormzControllerContext $formzControllerContext |
|
128
|
|
|
*/ |
|
129
|
|
|
public function injectFormzControllerContext(FormzControllerContext $formzControllerContext) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->formzControllerContext = $formzControllerContext; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param HashService $hashService |
|
136
|
|
|
*/ |
|
137
|
|
|
public function injectHashService(HashService $hashService) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->hashService = $hashService; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: