TYPO3  7.6
extbase/Classes/Mvc/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 = array();
78 
87  protected $internalArguments = array();
88 
92  protected $format = 'txt';
93 
97  protected $dispatched = false;
98 
104  protected $originalRequest = null;
105 
112 
120  public function setDispatched($flag)
121  {
122  $this->dispatched = (bool)$flag;
123  }
124 
135  public function isDispatched()
136  {
137  return $this->dispatched;
138  }
139 
148  public function getControllerObjectName()
149  {
150  if (null !== $this->controllerVendorName) {
151  // It's safe to assume a namespaced name as namespaced names have to follow PSR-0
152  $objectName = str_replace(
153  array(
154  '@extension',
155  '@subpackage',
156  '@controller',
157  '@vendor',
158  '\\\\'
159  ),
160  array(
161  $this->controllerExtensionName,
162  $this->controllerSubpackageKey,
163  $this->controllerName,
164  $this->controllerVendorName,
165  '\\'
166  ),
167  $this->namespacedControllerObjectNamePattern
168  );
169  } else {
170  $objectName = str_replace(
171  array(
172  '@extension',
173  '@subpackage',
174  '@controller',
175  '__'
176  ),
177  array(
178  $this->controllerExtensionName,
179  $this->controllerSubpackageKey,
180  $this->controllerName,
181  '_'
182  ),
183  $this->controllerObjectNamePattern
184  );
185  }
186  // @todo implement getCaseSensitiveObjectName()
187  if ($objectName === false) {
188  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchControllerException('The controller object "' . $objectName . '" does not exist.', 1220884009);
189  }
190  return $objectName;
191  }
192 
200  public function setControllerObjectName($controllerObjectName)
201  {
202  $nameParts = ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
203  $this->controllerVendorName = isset($nameParts['vendorName']) ? $nameParts['vendorName'] : null;
204  $this->controllerExtensionName = $nameParts['extensionName'];
205  $this->controllerSubpackageKey = isset($nameParts['subpackageKey']) ? $nameParts['subpackageKey'] : null;
206  $this->controllerName = $nameParts['controllerName'];
207  }
208 
216  public function setPluginName($pluginName = null)
217  {
218  if ($pluginName !== null) {
219  $this->pluginName = $pluginName;
220  }
221  }
222 
229  public function getPluginName()
230  {
231  return $this->pluginName;
232  }
233 
243  {
244  if ($controllerExtensionName !== null) {
245  $this->controllerExtensionName = $controllerExtensionName;
246  }
247  }
248 
255  public function getControllerExtensionName()
256  {
258  }
259 
266  public function getControllerExtensionKey()
267  {
268  return \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->controllerExtensionName);
269  }
270 
278  public function setControllerSubpackageKey($subpackageKey)
279  {
280  $this->controllerSubpackageKey = $subpackageKey;
281  }
282 
289  public function getControllerSubpackageKey()
290  {
292  }
293 
304  {
305  if (!is_string($controllerName) && $controllerName !== null) {
306  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must be a valid string, ' . gettype($controllerName) . ' given.', 1187176358);
307  }
308  if (strpos($controllerName, '_') !== false) {
309  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must not contain underscores.', 1217846412);
310  }
311  if ($controllerName !== null) {
312  $this->controllerName = $controllerName;
313  }
314  }
315 
323  public function getControllerName()
324  {
325  return $this->controllerName;
326  }
327 
338  public function setControllerActionName($actionName)
339  {
340  if (!is_string($actionName) && $actionName !== null) {
341  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException('The action name must be a valid string, ' . gettype($actionName) . ' given (' . $actionName . ').', 1187176359);
342  }
343  if ($actionName[0] !== strtolower($actionName[0]) && $actionName !== null) {
344  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);
345  }
346  if ($actionName !== null) {
347  $this->controllerActionName = $actionName;
348  }
349  }
350 
357  public function getControllerActionName()
358  {
359  $controllerObjectName = $this->getControllerObjectName();
360  if ($controllerObjectName !== '' && $this->controllerActionName === strtolower($this->controllerActionName)) {
361  $actionMethodName = $this->controllerActionName . 'Action';
362  $classMethods = get_class_methods($controllerObjectName);
363  if (is_array($classMethods)) {
364  foreach ($classMethods as $existingMethodName) {
365  if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
366  $this->controllerActionName = substr($existingMethodName, 0, -6);
367  break;
368  }
369  }
370  }
371  }
373  }
374 
384  public function setArgument($argumentName, $value)
385  {
386  if (!is_string($argumentName) || $argumentName === '') {
387  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException('Invalid argument name.', 1210858767);
388  }
389  if ($argumentName[0] === '_' && $argumentName[1] === '_') {
390  $this->internalArguments[$argumentName] = $value;
391  return;
392  }
393  switch ($argumentName) {
394  case '@extension':
395  $this->setControllerExtensionName($value);
396  break;
397  case '@subpackage':
398  $this->setControllerSubpackageKey($value);
399  break;
400  case '@controller':
401  $this->setControllerName($value);
402  break;
403  case '@action':
404  $this->setControllerActionName($value);
405  break;
406  case '@format':
407  $this->setFormat($value);
408  break;
409  case '@vendor':
410  $this->setControllerVendorName($value);
411  break;
412  default:
413  $this->arguments[$argumentName] = $value;
414  }
415  }
416 
424  public function setControllerVendorName($vendorName)
425  {
426  $this->controllerVendorName = $vendorName;
427  }
428 
434  public function getControllerVendorName()
435  {
437  }
438 
447  public function setArguments(array $arguments)
448  {
449  $this->arguments = array();
450  foreach ($arguments as $argumentName => $argumentValue) {
451  $this->setArgument($argumentName, $argumentValue);
452  }
453  }
454 
461  public function getArguments()
462  {
463  return $this->arguments;
464  }
465 
475  public function getArgument($argumentName)
476  {
477  if (!isset($this->arguments[$argumentName])) {
478  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
479  }
480  return $this->arguments[$argumentName];
481  }
482 
491  public function hasArgument($argumentName)
492  {
493  return isset($this->arguments[$argumentName]);
494  }
495 
503  public function setFormat($format)
504  {
505  $this->format = $format;
506  }
507 
514  public function getFormat()
515  {
516  return $this->format;
517  }
518 
524  public function getOriginalRequest()
525  {
526  return $this->originalRequest;
527  }
528 
534  public function setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
535  {
536  $this->originalRequest = $originalRequest;
537  }
538 
545  {
546  if ($this->originalRequestMappingResults === null) {
547  return new \TYPO3\CMS\Extbase\Error\Result();
548  }
550  }
551 
555  public function setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
556  {
557  $this->originalRequestMappingResults = $originalRequestMappingResults;
558  }
559 
566  public function getInternalArguments()
567  {
569  }
570 
578  public function getInternalArgument($argumentName)
579  {
580  if (!isset($this->internalArguments[$argumentName])) {
581  return null;
582  }
583  return $this->internalArguments[$argumentName];
584  }
585 }