[CLEANUP] Extbase mvc classes 42/29342/10
authorMarkus Klein <klein.t3@mfc-linz.at>
Thu, 10 Apr 2014 15:43:25 +0000 (17:43 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 5 Jul 2014 20:07:47 +0000 (22:07 +0200)
Add lots of type hints and some checks if the correct class is present.

Resolves: #57812
Releases: 6.3
Change-Id: I6f5e4d30dfbfb73cedf10c0efdbb271ee3bdcecf
Reviewed-on: https://review.typo3.org/29342
Reviewed-by: Oliver Klee
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
15 files changed:
typo3/sysext/extbase/Classes/Error/Result.php
typo3/sysext/extbase/Classes/Mvc/Cli/CommandManager.php
typo3/sysext/extbase/Classes/Mvc/Controller/AbstractController.php
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Classes/Mvc/Controller/Argument.php
typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php
typo3/sysext/extbase/Classes/Mvc/Controller/ArgumentsValidator.php
typo3/sysext/extbase/Classes/Mvc/Controller/CommandController.php
typo3/sysext/extbase/Classes/Mvc/Request.php
typo3/sysext/extbase/Classes/Mvc/View/JsonView.php
typo3/sysext/extbase/Classes/Mvc/Web/BackendRequestHandler.php
typo3/sysext/extbase/Classes/Mvc/Web/FrontendRequestHandler.php
typo3/sysext/extbase/Classes/Mvc/Web/RequestBuilder.php
typo3/sysext/extbase/Classes/Mvc/Web/Response.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php

index b8b0ccc..305146f 100644 (file)
@@ -462,7 +462,7 @@ class Result {
        /**
         * Get a list of all sub Result objects available.
         *
-        * @return array<\TYPO3\CMS\Extbase\Error\Result>
+        * @return \TYPO3\CMS\Extbase\Error\Result[]
         */
        public function getSubResults() {
                return $this->propertyResults;
index 3bdf564..28a8158 100644 (file)
@@ -39,7 +39,7 @@ class CommandManager implements \TYPO3\CMS\Core\SingletonInterface {
        /**
         * Returns an array of all commands
         *
-        * @return array<\TYPO3\CMS\Extbase\Mvc\Cli\Command>
+        * @return Command[]
         * @api
         */
        public function getAvailableCommands() {
@@ -66,7 +66,7 @@ class CommandManager implements \TYPO3\CMS\Core\SingletonInterface {
         * If more than one Command matches an AmbiguousCommandIdentifierException is thrown that contains the matched Commands
         *
         * @param string $commandIdentifier command identifier in the format foo:bar:baz
-        * @return \TYPO3\CMS\Extbase\Mvc\Cli\Command
+        * @return Command
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException if no matching command is available
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\AmbiguousCommandIdentifierException if more than one Command matches the identifier (the exception contains the matched commands)
         * @api
@@ -95,11 +95,11 @@ class CommandManager implements \TYPO3\CMS\Core\SingletonInterface {
        /**
         * Returns the shortest, non-ambiguous command identifier for the given command
         *
-        * @param \TYPO3\CMS\Extbase\Mvc\Cli\Command $command The command
+        * @param Command $command The command
         * @return string The shortest possible command identifier
         * @api
         */
-       public function getShortestIdentifierForCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command) {
+       public function getShortestIdentifierForCommand(Command $command) {
                if ($command->getCommandIdentifier() === 'extbase:help:help') {
                        return 'help';
                }
@@ -144,11 +144,11 @@ class CommandManager implements \TYPO3\CMS\Core\SingletonInterface {
         * Returns TRUE if the specified command identifier matches the identifier of the specified command.
         * This is the case, if the identifiers are the same or if at least the last two command parts match (case sensitive).
         *
-        * @param \TYPO3\CMS\Extbase\Mvc\Cli\Command $command
+        * @param Command $command
         * @param string $commandIdentifier command identifier in the format foo:bar:baz (all lower case)
         * @return boolean TRUE if the specified command identifier matches this commands identifier
         */
-       protected function commandMatchesIdentifier(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command, $commandIdentifier) {
+       protected function commandMatchesIdentifier(Command $command, $commandIdentifier) {
                $commandIdentifierParts = explode(':', $command->getCommandIdentifier());
                $searchedCommandIdentifierParts = explode(':', $commandIdentifier);
                $extensionKey = array_shift($commandIdentifierParts);
index 06cebf1..d69ef41 100644 (file)
@@ -13,12 +13,17 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
+use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
+use TYPO3\CMS\Extbase\Mvc\Web\Request as WebRequest;
+
 /**
  * An abstract base class for Controllers
  *
  * @api
  */
-abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface {
+abstract class AbstractController implements ControllerInterface {
 
        /**
         * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
@@ -52,7 +57,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        /**
         * The current request.
         *
-        * @var \TYPO3\CMS\Extbase\Mvc\Request
+        * @var \TYPO3\CMS\Extbase\Mvc\RequestInterface
         * @api
         */
        protected $request;
@@ -60,7 +65,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        /**
         * The response which will be returned by this action controller
         *
-        * @var \TYPO3\CMS\Extbase\Mvc\Response
+        * @var \TYPO3\CMS\Extbase\Mvc\ResponseInterface
         * @api
         */
        protected $response;
@@ -93,7 +98,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        protected $argumentsMappingResults;
 
        /**
-        * An array of supported request types. By default only web requests are supported.
+        * An array of supported request types.
         * Modify or replace this array if your specific controller supports certain
         * (additional) request types.
         *
@@ -122,7 +127,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        protected $flashMessageContainer;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        * @var ConfigurationManagerInterface
         */
        protected $configurationManager;
 
@@ -145,12 +150,12 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+        * @param ConfigurationManagerInterface $configurationManager
         * @return void
         */
-       public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
+       public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) {
                $this->configurationManager = $configurationManager;
-               $this->settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
+               $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
        }
 
        /**
@@ -204,7 +209,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * Checks if the current request type is supported by the controller.
         *
         * If your controller only supports certain request types, either
-        * replace / modify the supporteRequestTypes property or override this
+        * replace / modify the supportedRequestTypes property or override this
         * method.
         *
         * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The current request
@@ -226,14 +231,16 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request object
         * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, modified by this handler
         * @return void
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException if the controller doesn't support the current request type
+        * @throws UnsupportedRequestTypeException if the controller doesn't support the current request type
         * @api
         */
        public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
                if (!$this->canProcessRequest($request)) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes), 1187701132);
+                       throw new UnsupportedRequestTypeException(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes), 1187701132);
+               }
+               if ($response instanceof \TYPO3\CMS\Extbase\Mvc\Web\Response && $request instanceof WebRequest) {
+                       $response->setRequest($request);
                }
-               $response->setRequest($request);
                $this->request = $request;
                $this->request->setDispatched(TRUE);
                $this->response = $response;
@@ -278,23 +285,25 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @param string $extensionName Name of the extension containing the controller to forward to. If not specified, the current extension is assumed.
         * @param array $arguments Arguments to pass to the target action
         * @return void
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
+        * @throws StopActionException
         * @see redirect()
         * @api
         */
        public function forward($actionName, $controllerName = NULL, $extensionName = NULL, array $arguments = NULL) {
                $this->request->setDispatched(FALSE);
-               $this->request->setControllerActionName($actionName);
-               if ($controllerName !== NULL) {
-                       $this->request->setControllerName($controllerName);
-               }
-               if ($extensionName !== NULL) {
-                       $this->request->setControllerExtensionName($extensionName);
+               if ($this->request instanceof WebRequest) {
+                       $this->request->setControllerActionName($actionName);
+                       if ($controllerName !== NULL) {
+                               $this->request->setControllerName($controllerName);
+                       }
+                       if ($extensionName !== NULL) {
+                               $this->request->setControllerExtensionName($extensionName);
+                       }
                }
                if ($arguments !== NULL) {
                        $this->request->setArguments($arguments);
                }
-               throw new \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException();
+               throw new StopActionException();
        }
 
        /**
@@ -313,14 +322,14 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @param integer $delay (optional) The delay in seconds. Default is no delay.
         * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other
         * @return void
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
+        * @throws UnsupportedRequestTypeException If the request is not a web request
+        * @throws StopActionException
         * @see forward()
         * @api
         */
        protected function redirect($actionName, $controllerName = NULL, $extensionName = NULL, array $arguments = NULL, $pageUid = NULL, $delay = 0, $statusCode = 303) {
-               if (!$this->request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException('redirect() only supports web requests.', 1220539734);
+               if (!$this->request instanceof WebRequest) {
+                       throw new UnsupportedRequestTypeException('redirect() only supports web requests.', 1220539734);
                }
                if ($controllerName === NULL) {
                        $controllerName = $this->request->getControllerName();
@@ -341,13 +350,13 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @param mixed $uri A string representation of a URI
         * @param integer $delay (optional) The delay in seconds. Default is no delay.
         * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
+        * @throws UnsupportedRequestTypeException If the request is not a web request
+        * @throws StopActionException
         * @api
         */
        protected function redirectToUri($uri, $delay = 0, $statusCode = 303) {
-               if (!$this->request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException('redirect() only supports web requests.', 1220539735);
+               if (!$this->request instanceof WebRequest) {
+                       throw new UnsupportedRequestTypeException('redirect() only supports web requests.', 1220539735);
                }
 
                $this->objectManager->get('TYPO3\CMS\Extbase\Service\CacheService')->clearCachesOfRegisteredPageIds();
@@ -355,9 +364,11 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
                $uri = $this->addBaseUriIfNecessary($uri);
                $escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');
                $this->response->setContent('<html><head><meta http-equiv="refresh" content="' . (int)$delay . ';url=' . $escapedUri . '"/></head></html>');
-               $this->response->setStatus($statusCode);
-               $this->response->setHeader('Location', (string) $uri);
-               throw new \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException();
+               if ($this->response instanceof \TYPO3\CMS\Extbase\Mvc\Web\Response) {
+                       $this->response->setStatus($statusCode);
+                       $this->response->setHeader('Location', (string) $uri);
+               }
+               throw new StopActionException();
        }
 
        /**
@@ -378,20 +389,22 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @param integer $statusCode The HTTP status code
         * @param string $statusMessage A custom HTTP status message
         * @param string $content Body content which further explains the status
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
+        * @throws UnsupportedRequestTypeException If the request is not a web request
+        * @throws StopActionException
         * @api
         */
        public function throwStatus($statusCode, $statusMessage = NULL, $content = NULL) {
-               if (!$this->request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException('throwStatus() only supports web requests.', 1220539739);
+               if (!$this->request instanceof WebRequest) {
+                       throw new UnsupportedRequestTypeException('throwStatus() only supports web requests.', 1220539739);
                }
-               $this->response->setStatus($statusCode, $statusMessage);
-               if ($content === NULL) {
-                       $content = $this->response->getStatus();
+               if ($this->response instanceof \TYPO3\CMS\Extbase\Mvc\Web\Response) {
+                       $this->response->setStatus($statusCode, $statusMessage);
+                       if ($content === NULL) {
+                               $content = $this->response->getStatus();
+                       }
                }
                $this->response->setContent($content);
-               throw new \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException();
+               throw new StopActionException();
        }
 
        /**
@@ -401,6 +414,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @return void
         */
        public function initializeControllerArgumentsBaseValidators() {
+               /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                foreach ($this->arguments as $argument) {
                        $validator = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
                        if ($validator !== NULL) {
@@ -417,6 +431,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         */
        protected function mapRequestArgumentsToControllerArguments() {
                if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
+                       /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                        foreach ($this->arguments as $argument) {
                                $argumentName = $argument->getName();
                                if ($this->request->hasArgument($argumentName)) {
@@ -430,7 +445,9 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
                        $optionalPropertyNames = array();
                        $allPropertyNames = $this->arguments->getArgumentNames();
                        foreach ($allPropertyNames as $propertyName) {
-                               if ($this->arguments[$propertyName]->isRequired() === FALSE) {
+                               /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
+                               $argument = $this->arguments[$propertyName];
+                               if (!$argument->isRequired()) {
                                        $optionalPropertyNames[] = $propertyName;
                                }
                        }
@@ -440,4 +457,4 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
                        $this->argumentsMappingResults = $this->deprecatedPropertyMapper->getMappingResults();
                }
        }
-}
+}
\ No newline at end of file
index 47ace0b..2180b0b 100644 (file)
@@ -15,13 +15,15 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
  */
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Extbase\Mvc\Web\Request as WebRequest;
+use TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator;
 
 /**
  * A multi action controller. This is by far the most common base class for Controllers.
  *
  * @api
  */
-class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController {
+class ActionController extends AbstractController {
 
        /**
         * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
@@ -103,19 +105,20 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
        protected $mvcPropertyMappingConfigurationService;
 
        /**
-        * Checks if the current request type is supported by the controller.
+        * The current request.
         *
-        * If your controller only supports certain request types, either
-        * replace / modify the supporteRequestTypes property or override this
-        * method.
-        *
-        * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The current request
+        * @var \TYPO3\CMS\Extbase\Mvc\Request
+        * @api
+        */
+       protected $request;
+
+       /**
+        * The response which will be returned by this action controller
         *
-        * @return boolean TRUE if this request type is supported, otherwise FALSE
+        * @var \TYPO3\CMS\Extbase\Mvc\Response
+        * @api
         */
-       public function canProcessRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request) {
-               return parent::canProcessRequest($request);
-       }
+       protected $response;
 
        /**
         * Handles a request. The result output is returned by altering the given response.
@@ -130,7 +133,8 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                if (!$this->canProcessRequest($request)) {
                        throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException(get_class($this) . ' does not support requests of type "' . get_class($request) . '". Supported types are: ' . implode(' ', $this->supportedRequestTypes), 1187701131);
                }
-               if ($response instanceof \TYPO3\CMS\Extbase\Mvc\Web\Response) {
+
+               if ($response instanceof \TYPO3\CMS\Extbase\Mvc\Web\Response && $request instanceof WebRequest) {
                        $response->setRequest($request);
                }
                $this->request = $request;
@@ -207,11 +211,12 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                                $dontValidateAnnotations = $methodTagsValues['dontvalidate'];
                        }
 
+                       /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                        foreach ($this->arguments as $argument) {
                                $validator = $parameterValidators[$argument->getName()];
                                if (array_search('$' . $argument->getName(), $dontValidateAnnotations) === FALSE) {
                                        $baseValidatorConjunction = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
-                                       if ($baseValidatorConjunction !== NULL) {
+                                       if ($baseValidatorConjunction !== NULL && $validator instanceof AbstractCompositeValidator) {
                                                $validator->addValidator($baseValidatorConjunction);
                                        }
                                }
@@ -236,12 +241,12 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                         */
 
                        $parameterValidators = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($this), $this->actionMethodName, $methodParameters);
-
+                       /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                        foreach ($this->arguments as $argument) {
                                $validator = $parameterValidators[$argument->getName()];
 
                                $baseValidatorConjunction = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
-                               if (count($baseValidatorConjunction) > 0) {
+                               if (count($baseValidatorConjunction) > 0  && $validator instanceof AbstractCompositeValidator) {
                                        $validator->addValidator($baseValidatorConjunction);
                                }
                                $argument->setValidator($validator);
@@ -277,6 +282,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
                        // enabled since Extbase 1.4.0.
                        $preparedArguments = array();
+                       /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                        foreach ($this->arguments as $argument) {
                                $preparedArguments[] = $argument->getValue();
                        }
@@ -312,6 +318,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                } else {
                        // @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
                        $preparedArguments = array();
+                       /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                        foreach ($this->arguments as $argument) {
                                $preparedArguments[] = $argument->getValue();
                        }
@@ -341,11 +348,10 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
        }
 
        /**
-        * Prepares a view for the current action and stores it in $this->view.
-        * By default, this method tries to locate a view with a name matching
-        * the current action.
+        * Prepares a view for the current action.
+        * By default, this method tries to locate a view with a name matching the current action.
         *
-        * @return string
+        * @return ViewInterface
         * @api
         */
        protected function resolveView() {
@@ -556,12 +562,19 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                                );
                                $this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
                        }
-                       $referringRequest = $this->request->getReferringRequest();
-                       if ($referringRequest !== NULL) {
-                               $originalRequest = clone $this->request;
-                               $this->request->setOriginalRequest($originalRequest);
-                               $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
-                               $this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
+                       if ($this->request instanceof WebRequest) {
+                               $referringRequest = $this->request->getReferringRequest();
+                               if ($referringRequest !== NULL) {
+                                       $originalRequest = clone $this->request;
+                                       $this->request->setOriginalRequest($originalRequest);
+                                       $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
+                                       $this->forward(
+                                               $referringRequest->getControllerActionName(),
+                                               $referringRequest->getControllerName(),
+                                               $referringRequest->getControllerExtensionName(),
+                                               $referringRequest->getArguments()
+                                       );
+                               }
                        }
                        $message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
                        return $message;
@@ -612,7 +625,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        // If the new property mapper is enabled, the request hash is not needed anymore.
                        return;
                }
-               if (!$this->request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
+               if (!$this->request instanceof WebRequest) {
                        return;
                }
                // We only want to check it for now for web requests.
@@ -621,8 +634,12 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                }
                // all good
                $verificationNeeded = FALSE;
+               /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
                foreach ($this->arguments as $argument) {
-                       if ($argument->getOrigin() == \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_NEWLY_CREATED || $argument->getOrigin() == \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE_AND_MODIFIED) {
+                       if (
+                               $argument->getOrigin() == \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_NEWLY_CREATED
+                               || $argument->getOrigin() == \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE_AND_MODIFIED
+                       ) {
                                $verificationNeeded = TRUE;
                        }
                }
@@ -672,4 +689,4 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
 
                return $result;
        }
-}
+}
\ No newline at end of file
index 75c616b..a85b3dd 100644 (file)
@@ -484,7 +484,7 @@ class Argument {
        }
 
        /**
-        * @return array<\TYPO3\CMS\Extbase\Error\Result> Validation errors which have occurred.
+        * @return \TYPO3\CMS\Extbase\Error\Result Validation errors which have occurred.
         * @api
         */
        public function getValidationResults() {
index fed7c93..dad9e02 100644 (file)
@@ -51,7 +51,7 @@ class Arguments extends \ArrayObject {
         * @return void
         */
        public function offsetSet($offset, $value) {
-               if (!$value instanceof \TYPO3\CMS\Extbase\Mvc\Controller\Argument) {
+               if (!$value instanceof Argument) {
                        throw new \InvalidArgumentException('Controller arguments must be valid TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument objects.', 1187953786);
                }
                $argumentName = $value->getName();
@@ -67,7 +67,7 @@ class Arguments extends \ArrayObject {
         * @return void
         */
        public function append($value) {
-               if (!$value instanceof \TYPO3\CMS\Extbase\Mvc\Controller\Argument) {
+               if (!$value instanceof Argument) {
                        throw new \InvalidArgumentException('Controller arguments must be valid TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument objects.', 1187953787);
                }
                $this->offsetSet(NULL, $value);
@@ -103,7 +103,7 @@ class Arguments extends \ArrayObject {
         * Returns the value at the specified index
         *
         * @param mixed $offset Offset
-        * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument The requested argument object
+        * @return Argument The requested argument object
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException if the argument does not exist
         */
        public function offsetGet($offset) {
@@ -123,10 +123,10 @@ class Arguments extends \ArrayObject {
         * @param string $dataType Name of one of the built-in data types
         * @param boolean $isRequired TRUE if this argument should be marked as required
         * @param mixed $defaultValue Default value of the argument. Only makes sense if $isRequired==FALSE
-        * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument The new argument
+        * @return Argument The new argument
         */
        public function addNewArgument($name, $dataType = 'Text', $isRequired = FALSE, $defaultValue = NULL) {
-               /** @var $argument \TYPO3\CMS\Extbase\Mvc\Controller\Argument */
+               /** @var $argument Argument */
                $argument = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', $name, $dataType);
                $argument->setRequired($isRequired);
                $argument->setDefaultValue($defaultValue);
@@ -141,10 +141,10 @@ class Arguments extends \ArrayObject {
         *
         * Note that the argument will be cloned, not referenced.
         *
-        * @param \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument The argument to add
+        * @param Argument $argument The argument to add
         * @return void
         */
-       public function addArgument(\TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument) {
+       public function addArgument(Argument $argument) {
                $this->offsetSet(NULL, $argument);
        }
 
@@ -152,7 +152,7 @@ class Arguments extends \ArrayObject {
         * Returns an argument specified by name
         *
         * @param string $argumentName Name of the argument to retrieve
-        * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument
+        * @return Argument
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
         */
        public function getArgument($argumentName) {
@@ -189,6 +189,7 @@ class Arguments extends \ArrayObject {
         */
        public function getArgumentShortNames() {
                $argumentShortNames = array();
+               /** @var Argument $argument */
                foreach ($this as $argument) {
                        $argumentShortNames[$argument->getShortName()] = TRUE;
                }
@@ -233,6 +234,7 @@ class Arguments extends \ArrayObject {
                if (in_array($argumentName, $this->getArgumentNames())) {
                        return $argumentName;
                }
+               /** @var Argument $argument */
                foreach ($this as $argument) {
                        if ($argumentName === $argument->getShortName()) {
                                return $argument->getName();
@@ -260,6 +262,7 @@ class Arguments extends \ArrayObject {
         */
        public function getValidationResults() {
                $results = new \TYPO3\CMS\Extbase\Error\Result();
+               /** @var Argument $argument */
                foreach ($this as $argument) {
                        $argumentValidationResults = $argument->getValidationResults();
                        if ($argumentValidationResults === NULL) {
index a8c551a..39e6df5 100644 (file)
@@ -70,6 +70,7 @@ class ArgumentsValidator extends \TYPO3\CMS\Extbase\Validation\Validator\Abstrac
                if (!$arguments instanceof \TYPO3\CMS\Extbase\Mvc\Controller\Arguments) {
                        throw new \InvalidArgumentException('Expected TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments, ' . gettype($arguments) . ' given.', 1241079562);
                }
+               /** @var Argument $argument */
                $argument = $arguments[$argumentName];
                $validatorConjunction = $argument->getValidator();
                if ($validatorConjunction === NULL) {
index ca1a96d..57c7a75 100644 (file)
@@ -20,7 +20,7 @@ use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
  *
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class CommandController implements \TYPO3\CMS\Extbase\Mvc\Controller\CommandControllerInterface {
+class CommandController implements CommandControllerInterface {
 
        const MAXIMUM_LINE_LENGTH = 79;
 
@@ -159,6 +159,7 @@ class CommandController implements \TYPO3\CMS\Extbase\Mvc\Controller\CommandCont
         * @return void
         */
        protected function mapRequestArgumentsToControllerArguments() {
+               /** @var Argument $argument */
                foreach ($this->arguments as $argument) {
                        $argumentName = $argument->getName();
                        if ($this->request->hasArgument($argumentName)) {
@@ -204,6 +205,7 @@ class CommandController implements \TYPO3\CMS\Extbase\Mvc\Controller\CommandCont
         */
        protected function callCommandMethod() {
                $preparedArguments = array();
+               /** @var Argument $argument */
                foreach ($this->arguments as $argument) {
                        $preparedArguments[] = $argument->getValue();
                }
@@ -264,11 +266,11 @@ class CommandController implements \TYPO3\CMS\Extbase\Mvc\Controller\CommandCont
         *
         * @param string $text Text to output
         * @param array $arguments Optional arguments to use for sprintf
-        * @return string
+        * @return void
         * @see output()
         */
        protected function outputLine($text = '', array $arguments = array()) {
-               return $this->output($text . PHP_EOL, $arguments);
+               $this->output($text . PHP_EOL, $arguments);
        }
 
        /**
index f02604f..7739e1f 100644 (file)
@@ -21,7 +21,7 @@ use TYPO3\CMS\Core\Utility\ClassNamingUtility;
  *
  * @api
  */
-class Request implements \TYPO3\CMS\Extbase\Mvc\RequestInterface {
+class Request implements RequestInterface {
 
        const PATTERN_MATCH_FORMAT = '/^[a-z0-9]{1,5}$/';
 
index 91988ae..794f2e4 100644 (file)
@@ -13,12 +13,14 @@ namespace TYPO3\CMS\Extbase\Mvc\View;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Mvc\Web\Response as WebResponse;
+
 /**
  * A JSON view
  *
  * @api
  */
-class JsonView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
+class JsonView extends AbstractView {
 
        /**
         * Definition for the class name exposure configuration,
@@ -182,14 +184,17 @@ class JsonView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
 
        /**
         * Transforms the value view variable to a serializable
-        * array represantion using a YAML view configuration and JSON encodes
+        * array representation using a YAML view configuration and JSON encodes
         * the result.
         *
         * @return string The JSON encoded variables
         * @api
         */
        public function render() {
-               $this->controllerContext->getResponse()->setHeader('Content-Type', 'application/json');
+               $response = $this->controllerContext->getResponse();
+               if ($response instanceof WebResponse) {
+                       $response->setHeader('Content-Type', 'application/json');
+               }
                $propertiesToRender = $this->renderArray();
                return json_encode($propertiesToRender);
        }
@@ -296,4 +301,4 @@ class JsonView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
                        return $propertiesToRender;
                }
        }
-}
+}
\ No newline at end of file
index 81668df..cba5d53 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
 /**
  * A request handler which can handle web requests invoked by the backend.
  */
-class BackendRequestHandler extends \TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler {
+class BackendRequestHandler extends AbstractRequestHandler {
 
        /**
         * Handles the web request. The response will automatically be sent to the client.
index fd3bd98..00b8e40 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
 /**
  * A request handler which can handle web requests invoked by the frontend.
  */
-class FrontendRequestHandler extends \TYPO3\CMS\Extbase\Mvc\Web\AbstractRequestHandler {
+class FrontendRequestHandler extends AbstractRequestHandler {
 
        /**
         * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
index ca8d8fc..d49323a 100644 (file)
@@ -13,6 +13,9 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Mvc\Exception as MvcException;
+
 /**
  * Builds a web request.
  */
@@ -85,16 +88,16 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
        protected $environmentService;
 
        /**
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception
+        * @throws MvcException
         * @return void
         */
        protected function loadDefaultValues() {
-               $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+               $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                if (empty($configuration['extensionName'])) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception('"extensionName" is not properly configured. Request can\'t be dispatched!', 1289843275);
+                       throw new MvcException('"extensionName" is not properly configured. Request can\'t be dispatched!', 1289843275);
                }
                if (empty($configuration['pluginName'])) {
-                       throw new \TYPO3\CMS\Extbase\Mvc\Exception('"pluginName" is not properly configured. Request can\'t be dispatched!', 1289843277);
+                       throw new MvcException('"pluginName" is not properly configured. Request can\'t be dispatched!', 1289843277);
                }
                if (!empty($configuration['vendorName'])) {
                        $this->vendorName = $configuration['vendorName'];
@@ -158,20 +161,20 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
         *
         * @param array $parameters
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerNameException
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception if the controller could not be resolved
+        * @throws MvcException if the controller could not be resolved
         * @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
         * @return string
         */
        protected function resolveControllerName(array $parameters) {
                if (!isset($parameters['controller']) || strlen($parameters['controller']) === 0) {
                        if (strlen($this->defaultControllerName) === 0) {
-                               throw new \TYPO3\CMS\Extbase\Mvc\Exception('The default controller for extension "' . $this->extensionName . '" and plugin "' . $this->pluginName . '" can not be determined. Please check for TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1316104317);
+                               throw new MvcException('The default controller for extension "' . $this->extensionName . '" and plugin "' . $this->pluginName . '" can not be determined. Please check for TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1316104317);
                        }
                        return $this->defaultControllerName;
                }
                $allowedControllerNames = array_keys($this->allowedControllerActions);
                if (!in_array($parameters['controller'], $allowedControllerNames)) {
-                       $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+                       $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                        if (isset($configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved']) && (boolean) $configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved']) {
                                throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException('The requested resource was not found', 1313857897);
                        } elseif (isset($configuration['mvc']['callDefaultActionIfActionCantBeResolved']) && (boolean) $configuration['mvc']['callDefaultActionIfActionCantBeResolved']) {
@@ -190,7 +193,7 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
         * @param string $controllerName
         * @param array $parameters
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidActionNameException
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception
+        * @throws MvcException
         * @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
         * @return string
         */
@@ -198,14 +201,14 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
                $defaultActionName = is_array($this->allowedControllerActions[$controllerName]) ? current($this->allowedControllerActions[$controllerName]) : '';
                if (!isset($parameters['action']) || strlen($parameters['action']) === 0) {
                        if (strlen($defaultActionName) === 0) {
-                               throw new \TYPO3\CMS\Extbase\Mvc\Exception('The default action can not be determined for controller "' . $controllerName . '". Please check TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1295479651);
+                               throw new MvcException('The default action can not be determined for controller "' . $controllerName . '". Please check TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::configurePlugin() in your ext_localconf.php.', 1295479651);
                        }
                        return $defaultActionName;
                }
                $actionName = $parameters['action'];
                $allowedActionNames = $this->allowedControllerActions[$controllerName];
                if (!in_array($actionName, $allowedActionNames)) {
-                       $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+                       $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                        if (isset($configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved']) && (boolean) $configuration['mvc']['throwPageNotFoundExceptionIfActionCantBeResolved']) {
                                throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException('The requested resource was not found', 1313857898);
                        } elseif (isset($configuration['mvc']['callDefaultActionIfActionCantBeResolved']) && (boolean) $configuration['mvc']['callDefaultActionIfActionCantBeResolved']) {
@@ -274,4 +277,4 @@ class RequestBuilder implements \TYPO3\CMS\Core\SingletonInterface {
                }
                return $fieldPaths;
        }
-}
+}
\ No newline at end of file
index 7d49415..4bb9b1b 100644 (file)
@@ -13,6 +13,10 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Backend\Template\DocumentTemplate;
+use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+
 /**
  * A web specific response implementation
  *
@@ -168,7 +172,7 @@ class Response extends \TYPO3\CMS\Extbase\Mvc\Response {
        /**
         * Returns the HTTP headers - including the status header - of this web response
         *
-        * @return string The HTTP headers
+        * @return string[] The HTTP headers
         * @api
         */
        public function getHeaders() {
@@ -232,12 +236,16 @@ class Response extends \TYPO3\CMS\Extbase\Mvc\Response {
                        throw new \InvalidArgumentException('The additiona header data must be of type String, ' . gettype($additionalHeaderData) . ' given.', 1237370877);
                }
                if ($this->request->isCached()) {
+                       /** @var PageRenderer $pageRenderer */
+                       $pageRenderer = NULL;
                        if ($this->environmentService->isEnvironmentInFrontendMode()) {
-                               $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
+                               $pageRenderer = $this->getTypoScriptFrontendController()->getPageRenderer();
                        } elseif ($this->environmentService->isEnvironmentInBackendMode()) {
-                               $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
+                               $pageRenderer = $this->getDocumentTemplate()->getPageRenderer();
+                       }
+                       if ($pageRenderer !== NULL) {
+                               $pageRenderer->addHeaderData($additionalHeaderData);
                        }
-                       $pageRenderer->addHeaderData($additionalHeaderData);
                } else {
                        $this->additionalHeaderData[] = $additionalHeaderData;
                }
@@ -274,9 +282,23 @@ class Response extends \TYPO3\CMS\Extbase\Mvc\Response {
         */
        public function shutdown() {
                if (count($this->getAdditionalHeaderData()) > 0) {
-                       $GLOBALS['TSFE']->additionalHeaderData[] = implode(chr(10), $this->getAdditionalHeaderData());
+                       $this->getTypoScriptFrontendController()->additionalHeaderData[] = implode(chr(10), $this->getAdditionalHeaderData());
                }
                $this->sendHeaders();
                return parent::shutdown();
        }
-}
+
+       /**
+        * @return TypoScriptFrontendController
+        */
+       protected function getTypoScriptFrontendController() {
+               return $GLOBALS['TSFE'];
+       }
+
+       /**
+        * @return DocumentTemplate
+        */
+       protected function getDocumentTemplate() {
+               return $GLOBALS['TBE_TEMPLATE'];
+       }
+}
\ No newline at end of file
index 642567d..8cf8d7b 100644 (file)
@@ -44,7 +44,7 @@ abstract class AbstractValidator implements ValidatorInterface {
        protected $options = array();
 
        /**
-        * @var array
+        * @var \TYPO3\CMS\Extbase\Mvc\Controller\ArgumentError[]
         * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1. You should use constructor parameter to set validation options.
         */
        protected $errors = array();