TYPO3 CMS  TYPO3_8-7
Request.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc;
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 
24 class Request implements RequestInterface
25 {
26  const PATTERN_MATCH_FORMAT = '/^[a-z0-9]{1,5}$/';
27 
33  protected $controllerObjectNamePattern = 'Tx_@extension_@subpackage_Controller_@controllerController';
34 
40  protected $namespacedControllerObjectNamePattern = '@vendor\@extension\@subpackage\Controller\@controllerController';
41 
45  protected $pluginName = '';
46 
50  protected $controllerExtensionName = null;
51 
55  protected $controllerVendorName = null;
56 
62  protected $controllerSubpackageKey = null;
63 
67  protected $controllerName = 'Standard';
68 
72  protected $controllerActionName = 'index';
73 
77  protected $arguments = [];
78 
87  protected $internalArguments = [];
88 
92  protected $format = 'txt';
93 
97  protected $dispatched = false;
98 
104  protected $originalRequest = null;
105 
112 
119  public function setDispatched($flag)
120  {
121  $this->dispatched = (bool)$flag;
122  }
123 
134  public function isDispatched()
135  {
136  return $this->dispatched;
137  }
138 
147  public function getControllerObjectName()
148  {
149  if (null !== $this->controllerVendorName) {
150  // It's safe to assume a namespaced name as namespaced names have to follow PSR-0
151  $objectName = str_replace(
152  [
153  '@extension',
154  '@subpackage',
155  '@controller',
156  '@vendor',
157  '\\\\'
158  ],
159  [
160  $this->controllerExtensionName,
161  $this->controllerSubpackageKey,
162  $this->controllerName,
163  $this->controllerVendorName,
164  '\\'
165  ],
166  $this->namespacedControllerObjectNamePattern
167  );
168  } else {
169  $objectName = str_replace(
170  [
171  '@extension',
172  '@subpackage',
173  '@controller',
174  '__'
175  ],
176  [
177  $this->controllerExtensionName,
178  $this->controllerSubpackageKey,
179  $this->controllerName,
180  '_'
181  ],
182  $this->controllerObjectNamePattern
183  );
184  }
185  // @todo implement getCaseSensitiveObjectName()
186  if ($objectName === false) {
187  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchControllerException('The controller object "' . $objectName . '" does not exist.', 1220884009);
188  }
189  return $objectName;
190  }
191 
197  public function setControllerObjectName($controllerObjectName)
198  {
199  $nameParts = ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
200  $this->controllerVendorName = isset($nameParts['vendorName']) ? $nameParts['vendorName'] : null;
201  $this->controllerExtensionName = $nameParts['extensionName'];
202  $this->controllerSubpackageKey = isset($nameParts['subpackageKey']) ? $nameParts['subpackageKey'] : null;
203  $this->controllerName = $nameParts['controllerName'];
204  }
205 
211  public function setPluginName($pluginName = null)
212  {
213  if ($pluginName !== null) {
214  $this->pluginName = $pluginName;
215  }
216  }
217 
224  public function getPluginName()
225  {
226  return $this->pluginName;
227  }
228 
237  {
238  if ($controllerExtensionName !== null) {
239  $this->controllerExtensionName = $controllerExtensionName;
240  }
241  }
242 
249  public function getControllerExtensionName()
250  {
252  }
253 
260  public function getControllerExtensionKey()
261  {
262  return \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->controllerExtensionName);
263  }
264 
270  public function setControllerSubpackageKey($subpackageKey)
271  {
272  $this->controllerSubpackageKey = $subpackageKey;
273  }
274 
281  public function getControllerSubpackageKey()
282  {
284  }
285 
295  {
296  if (!is_string($controllerName) && $controllerName !== null) {
297  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must be a valid string, ' . gettype($controllerName) . ' given.', 1187176358);
298  }
299  if (strpos($controllerName, '_') !== false) {
300  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must not contain underscores.', 1217846412);
301  }
302  if ($controllerName !== null) {
303  $this->controllerName = $controllerName;
304  }
305  }
306 
314  public function getControllerName()
315  {
316  return $this->controllerName;
317  }
318 
328  public function setControllerActionName($actionName)
329  {
330  if (!is_string($actionName) && $actionName !== null) {
331  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException('The action name must be a valid string, ' . gettype($actionName) . ' given (' . $actionName . ').', 1187176359);
332  }
333  if ($actionName[0] !== strtolower($actionName[0]) && $actionName !== null) {
334  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);
335  }
336  if ($actionName !== null) {
337  $this->controllerActionName = $actionName;
338  }
339  }
340 
347  public function getControllerActionName()
348  {
349  $controllerObjectName = $this->getControllerObjectName();
350  if ($controllerObjectName !== '' && $this->controllerActionName === strtolower($this->controllerActionName)) {
351  $actionMethodName = $this->controllerActionName . 'Action';
352  $classMethods = get_class_methods($controllerObjectName);
353  if (is_array($classMethods)) {
354  foreach ($classMethods as $existingMethodName) {
355  if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
356  $this->controllerActionName = substr($existingMethodName, 0, -6);
357  break;
358  }
359  }
360  }
361  }
363  }
364 
373  public function setArgument($argumentName, $value)
374  {
375  if (!is_string($argumentName) || $argumentName === '') {
376  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException('Invalid argument name.', 1210858767);
377  }
378  if ($argumentName[0] === '_' && $argumentName[1] === '_') {
379  $this->internalArguments[$argumentName] = $value;
380  return;
381  }
382  if (!in_array($argumentName, ['@extension', '@subpackage', '@controller', '@action', '@format', '@vendor'], true)) {
383  $this->arguments[$argumentName] = $value;
384  }
385  }
386 
392  public function setControllerVendorName($vendorName)
393  {
394  $this->controllerVendorName = $vendorName;
395  }
396 
402  public function getControllerVendorName()
403  {
405  }
406 
413  public function setArguments(array $arguments)
414  {
415  $this->arguments = [];
416  foreach ($arguments as $argumentName => $argumentValue) {
417  $this->setArgument($argumentName, $argumentValue);
418  }
419  }
420 
427  public function getArguments()
428  {
429  return $this->arguments;
430  }
431 
441  public function getArgument($argumentName)
442  {
443  if (!isset($this->arguments[$argumentName])) {
444  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
445  }
446  return $this->arguments[$argumentName];
447  }
448 
457  public function hasArgument($argumentName)
458  {
459  return isset($this->arguments[$argumentName]);
460  }
461 
467  public function setFormat($format)
468  {
469  $this->format = $format;
470  }
471 
478  public function getFormat()
479  {
480  return $this->format;
481  }
482 
488  public function getOriginalRequest()
489  {
490  return $this->originalRequest;
491  }
492 
496  public function setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
497  {
498  $this->originalRequest = $originalRequest;
499  }
500 
507  {
508  if ($this->originalRequestMappingResults === null) {
509  return new \TYPO3\CMS\Extbase\Error\Result();
510  }
512  }
513 
517  public function setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
518  {
519  $this->originalRequestMappingResults = $originalRequestMappingResults;
520  }
521 
528  public function getInternalArguments()
529  {
531  }
532 
540  public function getInternalArgument($argumentName)
541  {
542  if (!isset($this->internalArguments[$argumentName])) {
543  return null;
544  }
545  return $this->internalArguments[$argumentName];
546  }
547 }
hasArgument($argumentName)
Definition: Request.php:457
setControllerName($controllerName)
Definition: Request.php:294
setControllerObjectName($controllerObjectName)
Definition: Request.php:197
static explodeObjectControllerName($controllerObjectName)
setArgument($argumentName, $value)
Definition: Request.php:373
setControllerActionName($actionName)
Definition: Request.php:328
setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
Definition: Request.php:517
getArgument($argumentName)
Definition: Request.php:441
getInternalArgument($argumentName)
Definition: Request.php:540
setArguments(array $arguments)
Definition: Request.php:413
setControllerExtensionName($controllerExtensionName)
Definition: Request.php:236
setPluginName($pluginName=null)
Definition: Request.php:211
setControllerSubpackageKey($subpackageKey)
Definition: Request.php:270
setControllerVendorName($vendorName)
Definition: Request.php:392
setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
Definition: Request.php:496