TYPO3 CMS  TYPO3_7-6
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 
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  [
154  '@extension',
155  '@subpackage',
156  '@controller',
157  '@vendor',
158  '\\\\'
159  ],
160  [
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  [
172  '@extension',
173  '@subpackage',
174  '@controller',
175  '__'
176  ],
177  [
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  if (!in_array($argumentName, ['@extension', '@subpackage', '@controller', '@action', '@format', '@vendor'], true)) {
394  $this->arguments[$argumentName] = $value;
395  }
396  }
397 
405  public function setControllerVendorName($vendorName)
406  {
407  $this->controllerVendorName = $vendorName;
408  }
409 
415  public function getControllerVendorName()
416  {
418  }
419 
428  public function setArguments(array $arguments)
429  {
430  $this->arguments = [];
431  foreach ($arguments as $argumentName => $argumentValue) {
432  $this->setArgument($argumentName, $argumentValue);
433  }
434  }
435 
442  public function getArguments()
443  {
444  return $this->arguments;
445  }
446 
456  public function getArgument($argumentName)
457  {
458  if (!isset($this->arguments[$argumentName])) {
459  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
460  }
461  return $this->arguments[$argumentName];
462  }
463 
472  public function hasArgument($argumentName)
473  {
474  return isset($this->arguments[$argumentName]);
475  }
476 
484  public function setFormat($format)
485  {
486  $this->format = $format;
487  }
488 
495  public function getFormat()
496  {
497  return $this->format;
498  }
499 
505  public function getOriginalRequest()
506  {
507  return $this->originalRequest;
508  }
509 
515  public function setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
516  {
517  $this->originalRequest = $originalRequest;
518  }
519 
526  {
527  if ($this->originalRequestMappingResults === null) {
528  return new \TYPO3\CMS\Extbase\Error\Result();
529  }
531  }
532 
536  public function setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
537  {
538  $this->originalRequestMappingResults = $originalRequestMappingResults;
539  }
540 
547  public function getInternalArguments()
548  {
550  }
551 
559  public function getInternalArgument($argumentName)
560  {
561  if (!isset($this->internalArguments[$argumentName])) {
562  return null;
563  }
564  return $this->internalArguments[$argumentName];
565  }
566 }
hasArgument($argumentName)
Definition: Request.php:472
setControllerName($controllerName)
Definition: Request.php:303
setControllerObjectName($controllerObjectName)
Definition: Request.php:200
static explodeObjectControllerName($controllerObjectName)
setArgument($argumentName, $value)
Definition: Request.php:384
setControllerActionName($actionName)
Definition: Request.php:338
setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
Definition: Request.php:536
getArgument($argumentName)
Definition: Request.php:456
getInternalArgument($argumentName)
Definition: Request.php:559
setArguments(array $arguments)
Definition: Request.php:428
setControllerExtensionName($controllerExtensionName)
Definition: Request.php:242
setPluginName($pluginName=null)
Definition: Request.php:216
setControllerSubpackageKey($subpackageKey)
Definition: Request.php:278
setControllerVendorName($vendorName)
Definition: Request.php:405
setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
Definition: Request.php:515