[TASK] Streamline CLI Request Handling 86/42386/5
authorBenjamin Mack <benni@typo3.org>
Fri, 7 Aug 2015 15:06:17 +0000 (17:06 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 8 Aug 2015 14:24:28 +0000 (16:24 +0200)
As the CLI Request Handlers and Http Request Handlers
are called only from their respective Application entrypoints,
the RequestHandlerInterface for Console Applications is
modified to reflect CLI-related Applications.

The currently only CliRequestHandler for Console is adapted
to have only a low priority.

Resolves: #68848
Releases: master
Change-Id: I0a252c18479aba6743147974b07286139a6bda98
Reviewed-on: http://review.typo3.org/42386
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Console/CliRequestHandler.php
typo3/sysext/core/Classes/Console/RequestHandlerInterface.php

index 6eeee9c..d831496 100644 (file)
@@ -19,6 +19,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
 use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Console\RequestHandlerInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Command Line Interface Request Handler dealing with "cliKey"-based Commands from the cli_dispatch.phpsh script.
@@ -47,15 +48,15 @@ class CliRequestHandler implements RequestHandlerInterface {
        /**
         * Handles any commandline request
         *
-        * @param InputInterface $request
+        * @param InputInterface $input
         * @return void
         */
-       public function handleRequest(InputInterface $request) {
-               $output = new ConsoleOutput();
+       public function handleRequest(InputInterface $input) {
+               $output = GeneralUtility::makeInstance(ConsoleOutput::class);
                $exitCode = 0;
 
                try {
-                       $command = $this->validateCommandLineKeyFromInput($request);
+                       $command = $this->validateCommandLineKeyFromInput($input);
 
                        // try and look up if the CLI command user exists, throws an exception if the CLI
                        // user cannot be found
@@ -169,7 +170,7 @@ class CliRequestHandler implements RequestHandlerInterface {
                if ($GLOBALS['BE_USER']->user['uid']) {
                        throw new \RuntimeException('Another user was already loaded which is impossible in CLI mode!', 3);
                }
-               if (!\TYPO3\CMS\Core\Utility\StringUtility::beginsWith($commandLineName, '_CLI_')) {
+               if (!StringUtility::beginsWith($commandLineName, '_CLI_')) {
                        throw new \RuntimeException('Module name, "' . $commandLineName . '", was not prefixed with "_CLI_"', 3);
                }
                $userName = strtolower($commandLineName);
@@ -185,11 +186,11 @@ class CliRequestHandler implements RequestHandlerInterface {
        /**
         * This request handler can handle any CLI request.
         *
-        * @param InputInterface $request
-        * @return bool If the request is a CLI request, TRUE otherwise FALSE
+        * @param InputInterface $input
+        * @return bool Always TRUE
         */
-       public function canHandleRequest(InputInterface $request) {
-               return defined('TYPO3_cliMode') && (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) && (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI);
+       public function canHandleRequest(InputInterface $input) {
+               return TRUE;
        }
 
        /**
@@ -198,6 +199,6 @@ class CliRequestHandler implements RequestHandlerInterface {
         * @return int The priority of the request handler.
         */
        public function getPriority() {
-               return 50;
+               return 20;
        }
 }
index 32cf549..656f794 100644 (file)
@@ -24,22 +24,22 @@ use Symfony\Component\Console\Output\OutputInterface;
 interface RequestHandlerInterface {
 
        /**
-        * Handles a raw request
+        * Handles a CLI request
         *
-        * @param InputInterface $request
+        * @param InputInterface $input
         * @return NULL|OutputInterface
         * @api
         */
-       public function handleRequest(InputInterface $request);
+       public function handleRequest(InputInterface $input);
 
        /**
         * Checks if the request handler can handle the given request.
         *
-        * @param InputInterface $request
+        * @param InputInterface $input
         * @return bool TRUE if it can handle the request, otherwise FALSE
         * @api
         */
-       public function canHandleRequest(InputInterface $request);
+       public function canHandleRequest(InputInterface $input);
 
        /**
         * Returns the priority - how eager the handler is to actually handle the