[TASK] Use CLI and Composer Checks via Environment class 27/57227/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 11:13:33 +0000 (13:13 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 15 Jun 2018 12:55:45 +0000 (14:55 +0200)
Use Environment::isCli() instead of constant munging
in various places. Usages in extbase are left out for
the time being since those give headaches with functional
frontend tests at the moment. Those will be sorted out
with further patches.

Resolves: #85271
Releases: master
Change-Id: I7391bb393eec69bf04fab0e6d31c8a579dc79493
Reviewed-on: https://review.typo3.org/57227
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
typo3/sysext/core/Classes/Authentication/CommandLineUserAuthentication.php
typo3/sysext/core/Classes/Messaging/FlashMessageRendererResolver.php
typo3/sysext/core/Classes/Utility/DebugUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/install/ext_localconf.php

index bb3edd2..f1a4101 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Authentication;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Crypto\Random;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -404,7 +405,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
         // Make certain that NO user is set initially
         $this->user = null;
         // Set all possible headers that could ensure that the script is not cached on the client-side
-        if ($this->sendNoCacheHeaders && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+        if ($this->sendNoCacheHeaders && !Environment::isCli()) {
             header('Expires: 0');
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
             $cacheControlHeader = 'no-cache, must-revalidate';
@@ -601,7 +602,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
             }
             // Refuse login for _CLI users, if not processing a CLI request type
             // (although we shouldn't be here in case of a CLI request type)
-            if (strtoupper(substr($loginData['uname'], 0, 5)) === '_CLI_' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+            if (strtoupper(substr($loginData['uname'], 0, 5)) === '_CLI_' && !Environment::isCli()) {
                 throw new \RuntimeException('TYPO3 Fatal Error: You have tried to login using a CLI user. Access prohibited!', 1270853931);
             }
         }
index 8b56001..77d5dba 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Authentication;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Crypto\Random;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -40,7 +41,7 @@ class CommandLineUserAuthentication extends BackendUserAuthentication
      */
     public function __construct()
     {
-        if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+        if (!Environment::isCli()) {
             throw new \RuntimeException('Creating a CLI-based user object on non-CLI level is not allowed', 1483971165);
         }
         if (!$this->isUserAllowedToLogin()) {
index 8752cb2..e3b9897 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Messaging;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -80,7 +81,7 @@ class FlashMessageRendererResolver
     protected function resolveContext(): string
     {
         $context = '';
-        if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
+        if (Environment::isCli()) {
             $context = 'CLI';
         } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
             $context = 'BE';
index a51b8f2..1d053f1 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Core\Utility;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
 
 /**
@@ -46,7 +48,7 @@ class DebugUtility
             ob_start();
         }
 
-        if (TYPO3_MODE === 'BE' && !self::isCommandLine()) {
+        if (TYPO3_MODE === 'BE' && !Environment::isCli()) {
             $debug = self::renderDump($var);
             $debugPlain = PHP_EOL . self::renderDump($var, '', true, false);
             $script = '
@@ -219,22 +221,12 @@ class DebugUtility
      */
     protected static function renderDump($variable, $title = '', $plainText = null, $ansiColors = null)
     {
-        $plainText = $plainText ?? self::isCommandLine() && self::$plainTextOutput;
-        $ansiColors = $ansiColors ?? self::isCommandLine() && self::$ansiColorUsage;
+        $plainText = $plainText ?? Environment::isCli() && self::$plainTextOutput;
+        $ansiColors = $ansiColors ?? Environment::isCli() && self::$ansiColorUsage;
         return trim(DebuggerUtility::var_dump($variable, $title, 8, $plainText, $ansiColors, true));
     }
 
     /**
-     * Checks some constants to determine if we are in CLI context
-     *
-     * @return bool
-     */
-    protected static function isCommandLine()
-    {
-        return (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) || PHP_SAPI === 'cli';
-    }
-
-    /**
      * Preset plaintext output
      *
      * Warning:
index 22925a6..58f4cc2 100644 (file)
@@ -2957,7 +2957,7 @@ class GeneralUtility
      */
     protected static function isInternalRequestType()
     {
-        return !defined('TYPO3_REQUESTTYPE') || (defined('TYPO3_REQUESTTYPE') && TYPO3_REQUESTTYPE & (TYPO3_REQUESTTYPE_INSTALL | TYPO3_REQUESTTYPE_CLI));
+        return Environment::isCli() || !defined('TYPO3_REQUESTTYPE') || (defined('TYPO3_REQUESTTYPE') && TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL);
     }
 
     /**
@@ -3045,7 +3045,7 @@ class GeneralUtility
     {
         $host = '';
         // If not called from the command-line, resolve on getIndpEnv()
-        if ($requestHost && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+        if ($requestHost && !Environment::isCli()) {
             $host = self::getIndpEnv('HTTP_HOST');
         }
         if (!$host) {
index 717dee3..075bb37 100644 (file)
@@ -44,7 +44,7 @@ class PathUtility
         if (self::isAbsolutePath($targetPath)) {
             if (strpos($targetPath, PATH_site) === 0) {
                 $targetPath = self::stripPathSitePrefix($targetPath);
-                if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+                if (!Environment::isCli()) {
                     $targetPath = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $targetPath;
                 }
             }
@@ -54,7 +54,7 @@ class PathUtility
             // Make an absolute path out of it
             $targetPath = GeneralUtility::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $targetPath);
             $targetPath = self::stripPathSitePrefix($targetPath);
-            if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+            if (!Environment::isCli()) {
                 $targetPath = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $targetPath;
             }
         }
index 59fc523..a8eb1bf 100644 (file)
@@ -86,7 +86,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['pr
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['security'][] = \TYPO3\CMS\Install\Report\SecurityStatusReport::class;
 
 // Only add the environment status report if not in CLI mode
-if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+if (!\TYPO3\CMS\Core\Core\Environment::isCli()) {
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['system'][] = \TYPO3\CMS\Install\Report\EnvironmentStatusReport::class;
 }