17 use Psr\Http\Message\ServerRequestInterface;
130 if (empty($configuration[
'extensionName'])) {
131 throw new MvcException(
'"extensionName" is not properly configured. Request can\'t be dispatched!', 1289843275);
133 if (empty($configuration[
'pluginName'])) {
134 throw new MvcException(
'"pluginName" is not properly configured. Request can\'t be dispatched!', 1289843277);
136 if (!empty($configuration[
'vendorName'])) {
137 $this->vendorName = $configuration[
'vendorName'];
139 $this->vendorName =
null;
141 $this->extensionName = $configuration[
'extensionName'];
142 $this->pluginName = $configuration[
'pluginName'];
143 $this->defaultControllerName = (string)current(array_keys($configuration[
'controllerConfiguration']));
144 $this->allowedControllerActions = [];
145 foreach ($configuration[
'controllerConfiguration'] as $controllerName => $controllerActions) {
146 $this->allowedControllerActions[$controllerName] = $controllerActions[
'actions'] ??
null;
148 if (!empty($configuration[
'format'])) {
149 $this->defaultFormat = $configuration[
'format'];
160 $pluginNamespace = $this->extensionService->getPluginNamespace($this->extensionName, $this->pluginName);
162 $typo3Request =
$GLOBALS[
'TYPO3_REQUEST'] ??
null;
163 if ($typo3Request instanceof ServerRequestInterface) {
164 $queryArguments = $typo3Request->getAttribute(
'routing');
165 if ($queryArguments instanceof PageArguments) {
166 $getParameters = $queryArguments->get($pluginNamespace) ?? [];
168 $getParameters = $typo3Request->getQueryParams()[$pluginNamespace] ?? [];
170 $bodyParameters = $typo3Request->getParsedBody()[$pluginNamespace] ?? [];
171 $bodyParameters = is_array($bodyParameters) ? $bodyParameters : [];
172 $parameters = is_array($getParameters) ? $getParameters : [];
175 $parameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged($pluginNamespace);
179 if (is_array($files[$pluginNamespace] ??
null)) {
180 $parameters = array_replace_recursive($parameters, $files[$pluginNamespace]);
186 $request = $this->objectManager->get(\
TYPO3\CMS\
Extbase\Mvc\Web\Request::class);
187 if ($this->vendorName !==
null) {
188 $request->setControllerVendorName($this->vendorName);
190 $request->setPluginName($this->pluginName);
191 $request->setControllerExtensionName($this->extensionName);
192 $request->setControllerName($controllerName);
193 $request->setControllerActionName($actionName);
195 $request->setRequestUri(\
TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(
'TYPO3_REQUEST_URL'));
196 $request->setBaseUri(\
TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(
'TYPO3_SITE_URL'));
197 $request->setMethod($this->environmentService->getServerRequestMethod());
198 if (isset($parameters[
'format']) && is_string($parameters[
'format']) && $parameters[
'format'] !==
'') {
199 $request->setFormat(filter_var($parameters[
'format'], FILTER_SANITIZE_STRING));
201 $request->setFormat($this->defaultFormat);
203 foreach ($parameters as $argumentName => $argumentValue) {
204 $request->setArgument($argumentName, $argumentValue);
222 if (!isset($parameters[
'controller']) || $parameters[
'controller'] ===
'') {
223 if (empty($this->defaultControllerName)) {
224 throw new MvcException(
'The default controller for extension "' . $this->extensionName .
'" and plugin "' . $this->pluginName .
'" can not be determined. Please check for TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1316104317);
228 $allowedControllerNames = array_keys($this->allowedControllerActions);
229 if (!in_array($parameters[
'controller'], $allowedControllerNames)) {
231 if (isset($configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved']) && (
bool)$configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved']) {
232 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException(
'The requested resource was not found', 1313857897);
234 if (isset($configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved']) && (
bool)$configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved']) {
237 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException(
238 'The controller "' . $parameters[
'controller'] .
'" is not allowed by plugin "' . $this->pluginName .
'". Please check for TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.',
242 return filter_var($parameters[
'controller'], FILTER_SANITIZE_STRING);
259 $defaultActionName = is_array($this->allowedControllerActions[$controllerName]) ? current($this->allowedControllerActions[$controllerName]) :
'';
260 if (!isset($parameters[
'action']) || $parameters[
'action'] ===
'') {
261 if ($defaultActionName ===
'') {
262 throw new MvcException(
'The default action can not be determined for controller "' . $controllerName .
'". Please check TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1295479651);
264 return $defaultActionName;
266 $actionName = $parameters[
'action'];
267 $allowedActionNames = $this->allowedControllerActions[$controllerName];
268 if (!in_array($actionName, $allowedActionNames)) {
270 if (isset($configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved']) && (
bool)$configuration[
'mvc'][
'throwPageNotFoundExceptionIfActionCantBeResolved']) {
271 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException(
'The requested resource was not found', 1313857898);
273 if (isset($configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved']) && (
bool)$configuration[
'mvc'][
'callDefaultActionIfActionCantBeResolved']) {
274 return $defaultActionName;
276 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException(
'The action "' . $actionName .
'" (controller "' . $controllerName .
'") is not allowed by this plugin / module. Please check TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php / TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configureModule() in your ext_tables.php.', 1313855175);
278 return filter_var($actionName, FILTER_SANITIZE_STRING);
289 $untangledFiles = [];
291 foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
292 if (!is_array($fieldInformation[
'error'])) {
293 $fieldPaths[] = [$firstLevelFieldName];
296 array_walk($newFieldPaths,
function (&$value, $key) {
297 $value = explode(
'/', $value);
299 $fieldPaths = array_merge($fieldPaths, $newFieldPaths);
302 foreach ($fieldPaths as $fieldPath) {
303 if (count($fieldPath) === 1) {
304 $fileInformation = $convolutedFiles[$fieldPath[0]];
306 $fileInformation = [];
307 foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) {
310 }
catch (MissingArrayPathException $e) {
317 return $untangledFiles;
330 if (is_array($structure)) {
331 foreach ($structure as $key => $subStructure) {
332 $fieldPath = ($firstLevelFieldName !==
null ? $firstLevelFieldName .
'/' :
'') . $key;
333 if (is_array($subStructure)) {
335 $fieldPaths[] = $fieldPath .
'/' . $subFieldPath;
338 $fieldPaths[] = $fieldPath;