‪TYPO3CMS  9.5
Request.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
23 {
24  const ‪PATTERN_MATCH_FORMAT = '/^[a-z0-9]{1,5}$/';
25 
31  protected ‪$namespacedControllerObjectNamePattern = '@vendor\@extension\@subpackage\Controller\@controllerController';
32 
36  protected ‪$pluginName = '';
37 
42 
46  protected ‪$controllerVendorName;
47 
54 
58  protected ‪$controllerName = 'Standard';
59 
63  protected ‪$controllerActionName = 'index';
64 
68  protected ‪$arguments = [];
69 
78  protected ‪$internalArguments = [];
79 
83  protected ‪$format = 'txt';
84 
88  protected ‪$dispatched = false;
89 
95  protected ‪$originalRequest;
96 
103 
109  public function ‪setDispatched($flag)
110  {
111  $this->dispatched = (bool)$flag;
112  }
113 
123  public function ‪isDispatched()
124  {
125  return ‪$this->dispatched;
126  }
127 
135  public function ‪getControllerObjectName()
136  {
137  $objectName = str_replace(
138  [
139  '@extension',
140  '@subpackage',
141  '@controller',
142  '@vendor',
143  '\\\\'
144  ],
145  [
146  $this->controllerExtensionName,
147  $this->controllerSubpackageKey,
148  $this->controllerName,
149  $this->controllerVendorName,
150  '\\'
151  ],
152  $this->namespacedControllerObjectNamePattern
153  );
154 
155  // @todo implement getCaseSensitiveObjectName()
156  if ($objectName === false) {
157  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchControllerException('The controller object "' . $objectName . '" does not exist.', 1220884009);
158  }
159  return $objectName;
160  }
161 
168  public function ‪setControllerObjectName($controllerObjectName)
169  {
170  $nameParts = ‪ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
171  $this->controllerVendorName = $nameParts['vendorName'] ?? null;
172  $this->controllerExtensionName = $nameParts['extensionName'];
173  $this->controllerSubpackageKey = $nameParts['subpackageKey'] ?? null;
174  $this->controllerName = $nameParts['controllerName'];
175  }
176 
183  public function ‪setPluginName(‪$pluginName = null)
184  {
185  if (‪$pluginName !== null) {
186  $this->pluginName = ‪$pluginName;
187  }
188  }
189 
195  public function ‪getPluginName()
196  {
197  return ‪$this->pluginName;
198  }
199 
208  {
209  if (‪$controllerExtensionName !== null) {
210  $this->controllerExtensionName = ‪$controllerExtensionName;
211  }
212  }
213 
219  public function ‪getControllerExtensionName()
220  {
222  }
223 
229  public function ‪getControllerExtensionKey()
230  {
231  return \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->controllerExtensionName);
232  }
233 
240  public function ‪setControllerSubpackageKey($subpackageKey)
241  {
242  $this->controllerSubpackageKey = $subpackageKey;
243  }
244 
253  {
255  }
256 
266  {
267  if (!is_string(‪$controllerName) && ‪$controllerName !== null) {
268  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must be a valid string, ' . gettype(‪$controllerName) . ' given.', 1187176358);
269  }
270  if (‪$controllerName !== null) {
271  $this->controllerName = ‪$controllerName;
272  }
273  }
274 
281  public function ‪getControllerName()
282  {
284  }
285 
295  public function ‪setControllerActionName($actionName)
296  {
297  if (!is_string($actionName) && $actionName !== null) {
298  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException('The action name must be a valid string, ' . gettype($actionName) . ' given (' . $actionName . ').', 1187176359);
299  }
300  if ($actionName[0] !== strtolower($actionName[0]) && $actionName !== null) {
301  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException('The action name must start with a lower case letter, "' . $actionName . '" does not match this criteria.', 1218473352);
302  }
303  if ($actionName !== null) {
304  $this->controllerActionName = $actionName;
305  }
306  }
307 
313  public function ‪getControllerActionName()
314  {
315  $controllerObjectName = $this->‪getControllerObjectName();
316  if ($controllerObjectName !== '' && $this->controllerActionName === strtolower($this->controllerActionName)) {
317  $actionMethodName = $this->controllerActionName . 'Action';
318  $classMethods = get_class_methods($controllerObjectName);
319  if (is_array($classMethods)) {
320  foreach ($classMethods as $existingMethodName) {
321  if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
322  $this->controllerActionName = substr($existingMethodName, 0, -6);
323  break;
324  }
325  }
326  }
327  }
329  }
330 
339  public function ‪setArgument($argumentName, $value)
340  {
341  if (!is_string($argumentName) || $argumentName === '') {
342  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException('Invalid argument name.', 1210858767);
343  }
344  if ($argumentName[0] === '_' && $argumentName[1] === '_') {
345  $this->internalArguments[$argumentName] = $value;
346  return;
347  }
348  if (!in_array($argumentName, ['@extension', '@subpackage', '@controller', '@action', '@format', '@vendor'], true)) {
349  $this->arguments[$argumentName] = $value;
350  }
351  }
352 
359  public function ‪setControllerVendorName($vendorName)
360  {
361  $this->controllerVendorName = $vendorName;
362  }
363 
370  public function ‪getControllerVendorName()
371  {
373  }
374 
382  public function ‪setArguments(array ‪$arguments)
383  {
384  $this->arguments = [];
385  foreach (‪$arguments as $argumentName => $argumentValue) {
386  $this->‪setArgument($argumentName, $argumentValue);
387  }
388  }
389 
395  public function ‪getArguments()
396  {
397  return ‪$this->arguments;
398  }
399 
408  public function ‪getArgument($argumentName)
409  {
410  if (!isset($this->arguments[$argumentName])) {
411  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
412  }
413  return $this->arguments[$argumentName];
414  }
415 
423  public function ‪hasArgument($argumentName)
424  {
425  return isset($this->arguments[$argumentName]);
426  }
427 
434  public function ‪setFormat(‪$format)
435  {
436  $this->format = ‪$format;
437  }
438 
444  public function ‪getFormat()
445  {
446  return ‪$this->format;
447  }
448 
455  public function ‪getOriginalRequest()
456  {
458  }
459 
464  public function ‪setOriginalRequest(\‪TYPO3\CMS\‪Extbase\Mvc\Request ‪$originalRequest)
465  {
466  $this->originalRequest = ‪$originalRequest;
467  }
468 
475  public function ‪getOriginalRequestMappingResults()
476  {
477  if ($this->originalRequestMappingResults === null) {
478  return new \TYPO3\CMS\Extbase\Error\Result();
479  }
481  }
482 
488  {
489  $this->originalRequestMappingResults = ‪$originalRequestMappingResults;
490  }
491 
499  public function ‪getInternalArguments()
500  {
502  }
503 
511  public function ‪getInternalArgument($argumentName)
512  {
513  if (!isset($this->internalArguments[$argumentName])) {
514  return null;
515  }
516  return $this->internalArguments[$argumentName];
517  }
518 }
‪TYPO3\CMS\Extbase\Mvc\Request\$format
‪string $format
Definition: Request.php:73
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerVendorName
‪string getControllerVendorName()
Definition: Request.php:357
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerObjectName
‪string getControllerObjectName()
Definition: Request.php:122
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3
‪TYPO3\CMS\Extbase\Mvc\Request\$namespacedControllerObjectNamePattern
‪string $namespacedControllerObjectNamePattern
Definition: Request.php:30
‪TYPO3\CMS\Extbase\Mvc\Request\setOriginalRequest
‪setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
Definition: Request.php:451
‪TYPO3\CMS\Extbase\Mvc\Request\getPluginName
‪string getPluginName()
Definition: Request.php:182
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerExtensionKey
‪string getControllerExtensionKey()
Definition: Request.php:216
‪TYPO3\CMS\Extbase\Mvc\Request\PATTERN_MATCH_FORMAT
‪const PATTERN_MATCH_FORMAT
Definition: Request.php:24
‪TYPO3\CMS\Extbase\Mvc
‪TYPO3\CMS\Extbase\Mvc\Request\$controllerName
‪string $controllerName
Definition: Request.php:52
‪TYPO3\CMS\Extbase\Mvc\Request\hasArgument
‪bool hasArgument($argumentName)
Definition: Request.php:410
‪TYPO3\CMS\Extbase\Mvc\Request\setArgument
‪setArgument($argumentName, $value)
Definition: Request.php:326
‪TYPO3\CMS\Extbase\Mvc\Request\$dispatched
‪bool $dispatched
Definition: Request.php:77
‪TYPO3\CMS\Extbase\Mvc\Request\getInternalArguments
‪array getInternalArguments()
Definition: Request.php:486
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerObjectName
‪setControllerObjectName($controllerObjectName)
Definition: Request.php:155
‪TYPO3\CMS\Extbase\Mvc\Request\$controllerActionName
‪string $controllerActionName
Definition: Request.php:56
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerActionName
‪setControllerActionName($actionName)
Definition: Request.php:282
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerSubpackageKey
‪setControllerSubpackageKey($subpackageKey)
Definition: Request.php:227
‪TYPO3\CMS\Extbase\Mvc\Request\getInternalArgument
‪string getInternalArgument($argumentName)
Definition: Request.php:498
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerSubpackageKey
‪string getControllerSubpackageKey()
Definition: Request.php:239
‪TYPO3\CMS\Extbase\Mvc\Request\isDispatched
‪bool isDispatched()
Definition: Request.php:110
‪TYPO3\CMS\Extbase\Mvc\Request\$internalArguments
‪array $internalArguments
Definition: Request.php:69
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array explodeObjectControllerName($controllerObjectName)
Definition: ClassNamingUtility.php:82
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerName
‪string getControllerName()
Definition: Request.php:268
‪TYPO3\CMS\Extbase\Mvc\Request\getArguments
‪array getArguments()
Definition: Request.php:382
‪TYPO3\CMS\Extbase\Mvc\Request\getOriginalRequestMappingResults
‪TYPO3 CMS Extbase Error Result getOriginalRequestMappingResults()
Definition: Request.php:462
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:23
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerExtensionName
‪setControllerExtensionName($controllerExtensionName)
Definition: Request.php:194
‪TYPO3\CMS\Extbase\Mvc\Request\setOriginalRequestMappingResults
‪setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
Definition: Request.php:474
‪TYPO3\CMS\Extbase\Mvc\Request\$controllerExtensionName
‪string $controllerExtensionName
Definition: Request.php:38
‪TYPO3\CMS\Extbase\Mvc\Request\setFormat
‪setFormat($format)
Definition: Request.php:421
‪TYPO3\CMS\Extbase\Mvc\Request\$pluginName
‪string $pluginName
Definition: Request.php:34
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerName
‪setControllerName($controllerName)
Definition: Request.php:252
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:21
‪TYPO3\CMS\Extbase\Mvc\Request\$controllerVendorName
‪string $controllerVendorName
Definition: Request.php:42
‪TYPO3\CMS\Extbase\Mvc\Request\$originalRequestMappingResults
‪TYPO3 CMS Extbase Error Result $originalRequestMappingResults
Definition: Request.php:89
‪TYPO3\CMS\Extbase\Mvc\Request\getFormat
‪string getFormat()
Definition: Request.php:431
‪TYPO3\CMS\Extbase\Mvc\Request\setDispatched
‪setDispatched($flag)
Definition: Request.php:96
‪TYPO3\CMS\Extbase\Mvc\Request\setArguments
‪setArguments(array $arguments)
Definition: Request.php:369
‪TYPO3\CMS\Extbase\Mvc\Request\$arguments
‪array $arguments
Definition: Request.php:60
‪TYPO3\CMS\Extbase\Mvc\Request\setPluginName
‪setPluginName($pluginName=null)
Definition: Request.php:170
‪TYPO3\CMS\Extbase\Mvc\Request\$controllerSubpackageKey
‪string $controllerSubpackageKey
Definition: Request.php:48
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerActionName
‪string getControllerActionName()
Definition: Request.php:300
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:23
‪TYPO3\CMS\Extbase\Mvc\Request\setControllerVendorName
‪setControllerVendorName($vendorName)
Definition: Request.php:346
‪TYPO3\CMS\Extbase\Mvc\Request\getOriginalRequest
‪TYPO3 CMS Extbase Mvc Request getOriginalRequest()
Definition: Request.php:442
‪TYPO3\CMS\Extbase\Mvc\Request\getControllerExtensionName
‪string getControllerExtensionName()
Definition: Request.php:206
‪TYPO3\CMS\Extbase\Mvc\Request\getArgument
‪string array getArgument($argumentName)
Definition: Request.php:395
‪TYPO3\CMS\Extbase\Mvc\Request\$originalRequest
‪TYPO3 CMS Extbase Mvc Request $originalRequest
Definition: Request.php:83