‪TYPO3CMS  ‪main
ExtbaseRequestParameters.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Extbase\Mvc;
19 
20 use Psr\Http\Message\UploadedFileInterface;
27 
35 {
42  protected string ‪$pluginName = '';
43 
49  protected string ‪$controllerExtensionName = '';
50 
55  protected string ‪$controllerObjectName = '';
56 
61  protected string ‪$controllerName = 'Standard';
62 
67 
73  protected string ‪$controllerActionName = 'index';
74 
79  protected array ‪$arguments = [];
80 
87  protected array ‪$internalArguments = [];
88 
93  protected string ‪$format = 'html';
94 
99 
104 
109  protected array ‪$uploadedFiles = [];
110 
111  public function ‪__construct(string $controllerClassName = '')
112  {
113  $this->controllerObjectName = $controllerClassName;
114  }
115 
116  public function ‪getControllerObjectName(): string
117  {
119  }
120 
122  {
124  $this->controllerExtensionName = $nameParts['extensionName'];
125  $this->controllerName = $nameParts['controllerName'];
126  return $this;
127  }
128 
129  public function ‪setPluginName(string ‪$pluginName): self
130  {
131  $this->pluginName = ‪$pluginName;
132  return $this;
133  }
134 
135  public function ‪getPluginName(): string
136  {
137  return ‪$this->pluginName;
138  }
139 
141  {
142  $this->controllerExtensionName = ‪$controllerExtensionName;
143  return $this;
144  }
145 
146  public function ‪getControllerExtensionName(): string
147  {
149  }
150 
151  public function ‪getControllerExtensionKey(): string
152  {
153  return ‪GeneralUtility::camelCaseToLowerCaseUnderscored($this->controllerExtensionName);
154  }
155 
157  {
158  // this is only needed as long as forwarded requests are altered and unless there
159  // is no new request object created by the request builder.
160  $this->controllerAliasToClassNameMapping = ‪$controllerAliasToClassNameMapping;
161  return $this;
162  }
163 
164  public function ‪setControllerName(string ‪$controllerName): self
165  {
166  $this->controllerName = ‪$controllerName;
167  // There might be no Controller Class, for example for Fluid Templates.
168  $this->controllerObjectName = $this->controllerAliasToClassNameMapping[‪$controllerName] ?? '';
169  return $this;
170  }
171 
172  public function ‪getControllerName(): string
173  {
175  }
176 
180  public function ‪setControllerActionName(string $actionName): self
181  {
182  if ($actionName[0] !== strtolower($actionName[0])) {
183  throw new ‪InvalidActionNameException('The action name must start with a lower case letter, "' . $actionName . '" does not match this criteria.', 1218473352);
184  }
185  $this->controllerActionName = $actionName;
186  return $this;
187  }
188 
189  public function ‪getControllerActionName(): string
190  {
192  if ($controllerObjectName !== '' && $this->controllerActionName === strtolower($this->controllerActionName)) {
193  // todo: this is nonsense! We can detect a non existing method in
194  // todo: \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin, if necessary.
195  // todo: At this point, we want to have a getter for a fixed value.
196  $actionMethodName = $this->controllerActionName . 'Action';
197  $classMethods = get_class_methods(‪$controllerObjectName);
198  if (is_array($classMethods)) {
199  foreach ($classMethods as $existingMethodName) {
200  if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
201  $this->controllerActionName = substr($existingMethodName, 0, -6);
202  break;
203  }
204  }
205  }
206  }
208  }
209 
214  public function ‪setArgument(string $argumentName, mixed $value): self
215  {
216  if ($argumentName === '') {
217  throw new ‪InvalidArgumentNameException('Invalid argument name.', 1210858767);
218  }
219  if (str_starts_with($argumentName, '__')) {
220  $this->internalArguments[$argumentName] = $value;
221  return $this;
222  }
223  if (!in_array($argumentName, ['@extension', '@subpackage', '@controller', '@action', '@format'], true)) {
224  $this->arguments[$argumentName] = $value;
225  }
226  return $this;
227  }
228 
235  public function ‪setArguments(array ‪$arguments): self
236  {
237  $this->arguments = [];
238  foreach (‪$arguments as $argumentName => $argumentValue) {
239  $this->‪setArgument($argumentName, $argumentValue);
240  }
241  return $this;
242  }
243 
244  public function ‪getArguments(): array
245  {
246  return ‪$this->arguments;
247  }
248 
255  public function ‪getArgument(string $argumentName): mixed
256  {
257  if (!isset($this->arguments[$argumentName])) {
258  throw new ‪NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
259  }
260  return $this->arguments[$argumentName];
261  }
262 
266  public function ‪hasArgument(string $argumentName = ''): bool
267  {
268  return isset($this->arguments[$argumentName]);
269  }
270 
271  public function ‪setFormat(string ‪$format): self
272  {
273  $this->format = ‪$format;
274  return $this;
275  }
276 
277  public function ‪getFormat(): string
278  {
279  return ‪$this->format;
280  }
281 
286  {
288  }
289 
291  {
292  $this->originalRequest = ‪$originalRequest;
293  return $this;
294  }
295 
297  {
298  if ($this->originalRequestMappingResults === null) {
299  return new ‪Result();
300  }
302  }
303 
305  {
306  $this->originalRequestMappingResults = ‪$originalRequestMappingResults;
307  return $this;
308  }
309 
315  public function ‪getInternalArgument($argumentName): mixed
316  {
317  if (!isset($this->internalArguments[$argumentName])) {
318  return null;
319  }
320  return $this->internalArguments[$argumentName];
321  }
322 
323  public function ‪getUploadedFiles(): array
324  {
326  }
327 
328  public function ‪setUploadedFiles(array $files): self
329  {
330  $this->‪validateUploadedFiles($files);
331  $this->uploadedFiles = $files;
332  return $this;
333  }
334 
340  protected function ‪validateUploadedFiles(array ‪$uploadedFiles): void
341  {
342  foreach (‪$uploadedFiles as $file) {
343  if (is_array($file)) {
344  $this->‪validateUploadedFiles($file);
345  continue;
346  }
347  if (!$file instanceof UploadedFileInterface) {
348  throw new \InvalidArgumentException('Invalid file in uploaded files structure.', 1647338470);
349  }
350  }
351  }
352 }
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$controllerExtensionName
‪string $controllerExtensionName
Definition: ExtbaseRequestParameters.php:49
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setControllerAliasToClassNameMapping
‪setControllerAliasToClassNameMapping(array $controllerAliasToClassNameMapping)
Definition: ExtbaseRequestParameters.php:156
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$controllerActionName
‪string $controllerActionName
Definition: ExtbaseRequestParameters.php:73
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$internalArguments
‪array $internalArguments
Definition: ExtbaseRequestParameters.php:87
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setArgument
‪setArgument(string $argumentName, mixed $value)
Definition: ExtbaseRequestParameters.php:214
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setControllerActionName
‪setControllerActionName(string $actionName)
Definition: ExtbaseRequestParameters.php:180
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getArguments
‪getArguments()
Definition: ExtbaseRequestParameters.php:244
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getPluginName
‪getPluginName()
Definition: ExtbaseRequestParameters.php:135
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getControllerObjectName
‪getControllerObjectName()
Definition: ExtbaseRequestParameters.php:116
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getControllerActionName
‪getControllerActionName()
Definition: ExtbaseRequestParameters.php:189
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setOriginalRequestMappingResults
‪setOriginalRequestMappingResults(Result $originalRequestMappingResults)
Definition: ExtbaseRequestParameters.php:304
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getOriginalRequest
‪getOriginalRequest()
Definition: ExtbaseRequestParameters.php:285
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getControllerExtensionName
‪getControllerExtensionName()
Definition: ExtbaseRequestParameters.php:146
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$arguments
‪array $arguments
Definition: ExtbaseRequestParameters.php:79
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getControllerName
‪getControllerName()
Definition: ExtbaseRequestParameters.php:172
‪TYPO3\CMS\Extbase\Mvc
‪TYPO3\CMS\Core\Utility\GeneralUtility\camelCaseToLowerCaseUnderscored
‪static string camelCaseToLowerCaseUnderscored($string)
Definition: GeneralUtility.php:678
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$originalRequestMappingResults
‪Result $originalRequestMappingResults
Definition: ExtbaseRequestParameters.php:103
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array< string > explodeObjectControllerName(string $controllerObjectName)
Definition: ClassNamingUtility.php:68
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setFormat
‪setFormat(string $format)
Definition: ExtbaseRequestParameters.php:271
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getFormat
‪getFormat()
Definition: ExtbaseRequestParameters.php:277
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setPluginName
‪setPluginName(string $pluginName)
Definition: ExtbaseRequestParameters.php:129
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getControllerExtensionKey
‪getControllerExtensionKey()
Definition: ExtbaseRequestParameters.php:151
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$uploadedFiles
‪array $uploadedFiles
Definition: ExtbaseRequestParameters.php:109
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setControllerObjectName
‪setControllerObjectName(string $controllerObjectName)
Definition: ExtbaseRequestParameters.php:121
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setUploadedFiles
‪setUploadedFiles(array $files)
Definition: ExtbaseRequestParameters.php:328
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setControllerExtensionName
‪setControllerExtensionName(string $controllerExtensionName)
Definition: ExtbaseRequestParameters.php:140
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$pluginName
‪string $pluginName
Definition: ExtbaseRequestParameters.php:42
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setArguments
‪setArguments(array $arguments)
Definition: ExtbaseRequestParameters.php:235
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\hasArgument
‪hasArgument(string $argumentName='')
Definition: ExtbaseRequestParameters.php:266
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$controllerAliasToClassNameMapping
‪array $controllerAliasToClassNameMapping
Definition: ExtbaseRequestParameters.php:66
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:28
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getInternalArgument
‪mixed getInternalArgument($argumentName)
Definition: ExtbaseRequestParameters.php:315
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getUploadedFiles
‪getUploadedFiles()
Definition: ExtbaseRequestParameters.php:323
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$controllerObjectName
‪string $controllerObjectName
Definition: ExtbaseRequestParameters.php:55
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$originalRequest
‪RequestInterface $originalRequest
Definition: ExtbaseRequestParameters.php:98
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\validateUploadedFiles
‪validateUploadedFiles(array $uploadedFiles)
Definition: ExtbaseRequestParameters.php:340
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$format
‪string $format
Definition: ExtbaseRequestParameters.php:93
‪TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
Definition: InvalidArgumentNameException.php:25
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setControllerName
‪setControllerName(string $controllerName)
Definition: ExtbaseRequestParameters.php:164
‪TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException
Definition: InvalidActionNameException.php:25
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\setOriginalRequest
‪setOriginalRequest(RequestInterface $originalRequest)
Definition: ExtbaseRequestParameters.php:290
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getArgument
‪mixed getArgument(string $argumentName)
Definition: ExtbaseRequestParameters.php:255
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\$controllerName
‪string $controllerName
Definition: ExtbaseRequestParameters.php:61
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\__construct
‪__construct(string $controllerClassName='')
Definition: ExtbaseRequestParameters.php:111
‪TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
Definition: NoSuchArgumentException.php:25
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters\getOriginalRequestMappingResults
‪getOriginalRequestMappingResults()
Definition: ExtbaseRequestParameters.php:296