TYPO3 CMS  TYPO3_6-2
Request.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc;
3 
18 
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 
117  protected $errors = array();
118 
127  public function setDispatched($flag) {
128  $this->dispatched = $flag ? TRUE : FALSE;
129  }
130 
141  public function isDispatched() {
142  return $this->dispatched;
143  }
144 
153  public function getControllerObjectName() {
154  if (NULL !== $this->controllerVendorName) {
155  // It's safe to assume a namespaced name as namespaced names have to follow PSR-0
156  $objectName = str_replace(
157  array(
158  '@extension',
159  '@subpackage',
160  '@controller',
161  '@vendor',
162  '\\\\'
163  ),
164  array(
165  $this->controllerExtensionName,
166  $this->controllerSubpackageKey,
167  $this->controllerName,
168  $this->controllerVendorName,
169  '\\'
170  ),
171  $this->namespacedControllerObjectNamePattern
172  );
173  } else {
174  $objectName = str_replace(
175  array(
176  '@extension',
177  '@subpackage',
178  '@controller',
179  '__'
180  ),
181  array(
182  $this->controllerExtensionName,
183  $this->controllerSubpackageKey,
184  $this->controllerName,
185  '_'
186  ),
187  $this->controllerObjectNamePattern
188  );
189  }
190  // TODO implement getCaseSensitiveObjectName()
191  if ($objectName === FALSE) {
192  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchControllerException('The controller object "' . $objectName . '" does not exist.', 1220884009);
193  }
194  return $objectName;
195  }
196 
204  public function setControllerObjectName($controllerObjectName) {
205  $nameParts = ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
206  $this->controllerVendorName = isset($nameParts['vendorName']) ? $nameParts['vendorName'] : NULL;
207  $this->controllerExtensionName = $nameParts['extensionName'];
208  $this->controllerSubpackageKey = isset($nameParts['subpackageKey']) ? $nameParts['subpackageKey'] : NULL;
209  $this->controllerName = $nameParts['controllerName'];
210  }
211 
219  public function setPluginName($pluginName = NULL) {
220  if ($pluginName !== NULL) {
221  $this->pluginName = $pluginName;
222  }
223  }
224 
231  public function getPluginName() {
232  return $this->pluginName;
233  }
234 
244  if ($controllerExtensionName !== NULL) {
245  $this->controllerExtensionName = $controllerExtensionName;
246  }
247  }
248 
255  public function getControllerExtensionName() {
257  }
258 
265  public function getControllerExtensionKey() {
266  return \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->controllerExtensionName);
267  }
268 
276  public function setControllerSubpackageKey($subpackageKey) {
277  $this->controllerSubpackageKey = $subpackageKey;
278  }
279 
286  public function getControllerSubpackageKey() {
288  }
289 
300  if (!is_string($controllerName) && $controllerName !== NULL) {
301  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must be a valid string, ' . gettype($controllerName) . ' given.', 1187176358);
302  }
303  if (strpos($controllerName, '_') !== FALSE) {
304  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException('The controller name must not contain underscores.', 1217846412);
305  }
306  if ($controllerName !== NULL) {
307  $this->controllerName = $controllerName;
308  }
309  }
310 
318  public function getControllerName() {
319  return $this->controllerName;
320  }
321 
332  public function setControllerActionName($actionName) {
333  if (!is_string($actionName) && $actionName !== NULL) {
334  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException('The action name must be a valid string, ' . gettype($actionName) . ' given (' . $actionName . ').', 1187176359);
335  }
336  if ($actionName[0] !== strtolower($actionName[0]) && $actionName !== NULL) {
337  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);
338  }
339  if ($actionName !== NULL) {
340  $this->controllerActionName = $actionName;
341  }
342  }
343 
350  public function getControllerActionName() {
351  $controllerObjectName = $this->getControllerObjectName();
352  if ($controllerObjectName !== '' && $this->controllerActionName === strtolower($this->controllerActionName)) {
353  $actionMethodName = $this->controllerActionName . 'Action';
354  $classMethods = get_class_methods($controllerObjectName);
355  if (is_array($classMethods)) {
356  foreach ($classMethods as $existingMethodName) {
357  if (strtolower($existingMethodName) === strtolower($actionMethodName)) {
358  $this->controllerActionName = substr($existingMethodName, 0, -6);
359  break;
360  }
361  }
362  }
363  }
365  }
366 
376  public function setArgument($argumentName, $value) {
377  if (!is_string($argumentName) || strlen($argumentName) == 0) {
378  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException('Invalid argument name.', 1210858767);
379  }
380  if ($argumentName[0] === '_' && $argumentName[1] === '_') {
381  $this->internalArguments[$argumentName] = $value;
382  return;
383  }
384  if (!in_array($argumentName, array('@extension', '@subpackage', '@controller', '@action', '@format', '@vendor'), TRUE)) {
385  $this->arguments[$argumentName] = $value;
386  }
387  }
388 
396  public function setControllerVendorName($vendorName) {
397  $this->controllerVendorName = $vendorName;
398  }
399 
405  public function getControllerVendorName() {
407  }
408 
417  public function setArguments(array $arguments) {
418  $this->arguments = array();
419  foreach ($arguments as $argumentName => $argumentValue) {
420  $this->setArgument($argumentName, $argumentValue);
421  }
422  }
423 
430  public function getArguments() {
431  return $this->arguments;
432  }
433 
443  public function getArgument($argumentName) {
444  if (!isset($this->arguments[$argumentName])) {
445  throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException('An argument "' . $argumentName . '" does not exist for this request.', 1176558158);
446  }
447  return $this->arguments[$argumentName];
448  }
449 
458  public function hasArgument($argumentName) {
459  return isset($this->arguments[$argumentName]);
460  }
461 
469  public function setFormat($format) {
470  $this->format = $format;
471  }
472 
479  public function getFormat() {
480  return $this->format;
481  }
482 
491  public function setErrors(array $errors) {
492  $this->errors = $errors;
493  }
494 
501  public function getErrors() {
502  return $this->errors;
503  }
504 
510  public function getOriginalRequest() {
511  return $this->originalRequest;
512  }
513 
519  public function setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest) {
520  $this->originalRequest = $originalRequest;
521  }
522 
529  if ($this->originalRequestMappingResults === NULL) {
530  return new \TYPO3\CMS\Extbase\Error\Result();
531  }
533  }
534 
538  public function setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults) {
539  $this->originalRequestMappingResults = $originalRequestMappingResults;
540  }
541 
548  public function getInternalArguments() {
550  }
551 
559  public function getInternalArgument($argumentName) {
560  if (!isset($this->internalArguments[$argumentName])) {
561  return NULL;
562  }
563  return $this->internalArguments[$argumentName];
564  }
565 }
hasArgument($argumentName)
Definition: Request.php:458
setControllerName($controllerName)
Definition: Request.php:299
setControllerObjectName($controllerObjectName)
Definition: Request.php:204
static explodeObjectControllerName($controllerObjectName)
setPluginName($pluginName=NULL)
Definition: Request.php:219
setArgument($argumentName, $value)
Definition: Request.php:376
setErrors(array $errors)
Definition: Request.php:491
setControllerActionName($actionName)
Definition: Request.php:332
setOriginalRequestMappingResults(\TYPO3\CMS\Extbase\Error\Result $originalRequestMappingResults)
Definition: Request.php:538
getArgument($argumentName)
Definition: Request.php:443
getInternalArgument($argumentName)
Definition: Request.php:559
setArguments(array $arguments)
Definition: Request.php:417
setControllerExtensionName($controllerExtensionName)
Definition: Request.php:243
setControllerSubpackageKey($subpackageKey)
Definition: Request.php:276
setControllerVendorName($vendorName)
Definition: Request.php:396
setOriginalRequest(\TYPO3\CMS\Extbase\Mvc\Request $originalRequest)
Definition: Request.php:519