[TASK] Move all init.php code in global scope into methods
authorHelmut Hummel <helmut.hummel@typo3.org>
Sun, 17 Jun 2012 10:33:14 +0000 (12:33 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 20 Jun 2012 11:45:37 +0000 (13:45 +0200)
There is some code left in init.php that is not yet encapsuled in methods.
Move everything into methods in the bootstrap class.

Remaining TYPO3_DB->connectToDatase() calls in other classes will be
handled in a different change.

Change-Id: If69b8cc49cb9ff04d18612d733414e36ee9a48fb
Resolves: #38132
Releases: 6.0
Reviewed-on: http://review.typo3.org/12152
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Reviewed-by: Oliver Hader
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/classes/Bootstrap.php
typo3/init.php

index d4da17b..b220b23 100644 (file)
@@ -69,6 +69,18 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Prevent any unwanted output that may corrupt AJAX/compression.
+        * This does not interfeer with "die()" or "echo"+"exit()" messages!
+        *
+        * @return Typo3_Bootstrap
+        */
+       public function startOutputBuffering() {
+               ob_start();
+
+               return $this;
+       }
+
+       /**
         * Check several a priori conditions like the current
         * php version or exit the script with an error.
         *
@@ -246,6 +258,22 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Throws an exception if no browser could be identified
+        *
+        * @return Typo3_Bootstrap
+        * @throws RuntimeException
+        */
+       public function checkValidBrowserOrDie() {
+                       // Checks for proper browser
+               if (empty($GLOBALS['CLIENT']['BROWSER'])) {
+                       throw new RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
+               }
+
+               return $this;
+       }
+
+
+       /**
         * Load default TYPO3_CONF_VARS
         *
         * @return Typo3_Bootstrap
@@ -396,6 +424,19 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Redirect to install tool if database host and database are not defined
+        *
+        * @return Typo3_Bootstrap
+        */
+       public function redirectToInstallToolIfDatabaseCredentialsAreMissing() {
+               if (!TYPO3_db_host && !TYPO3_db) {
+                       t3lib_utility_Http::redirect('install/index.php?mode=123&step=1&password=joh316');
+               }
+
+               return $this;
+       }
+
+       /**
         * Initialize caching framework
         *
         * @return Typo3_Bootstrap
@@ -946,7 +987,7 @@ class Typo3_Bootstrap {
                $GLOBALS['TYPO3_DB'] = t3lib_div::makeInstance('t3lib_DB');
                $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
                if ($connect) {
-                       $GLOBALS['TYPO3_DB']->connectDB();
+                       $this->establishDatabaseConnection();
                }
 
                return $this;
@@ -1048,6 +1089,17 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Establish connection to the database
+        *
+        * @return Typo3_Bootstrap
+        */
+       public function establishDatabaseConnection() {
+               $GLOBALS['TYPO3_DB']->connectDB();
+
+               return $this;
+       }
+
+       /**
         * Load ext_tables and friends.
         *
         * This will mainly set up $TCA and several other global arrays
@@ -1192,6 +1244,33 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Throw away all output that may have happened during bootstrapping by weird extensions
+        *
+        * @return Typo3_Bootstrap
+        */
+       public function endOutputBufferingAndCleanPreviousOutput() {
+               ob_clean();
+
+               return $this;
+       }
+
+       /**
+        * Initialize output compression if configured
+        *
+        * @return Typo3_Bootstrap
+        */
+       public function initializeOutputCompression() {
+               if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
+                       if (t3lib_utility_Math::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
+                               @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
+                       }
+                       ob_start('ob_gzhandler');
+               }
+
+               return $this;
+       }
+
+       /**
         * Things that should be performed to shut down the framework.
         * This method is called in all important scripts for a clean
         * shut down of the system.
index 32f5907..d596ccf 100644 (file)
  * @subpackage core
  */
 
-       // Prevent any unwanted output that may corrupt AJAX/compression. Note: this does
-       // not interfeer with "die()" or "echo"+"exit()" messages!
-ob_start();
-
-       // Define constants
 define('TYPO3_MODE', 'BE');
 
        // We use require instead of require_once here so we get a fatal error if
        // classes/Bootstrap.php is accidentally included twice (which would indicate a clear bug).
 require('classes/Bootstrap.php');
 Typo3_Bootstrap::getInstance()
+       ->startOutputBuffering()
        ->checkEnvironmentOrDie()
        ->defineBaseConstants()
        ->defineAndCheckPaths('typo3/')
@@ -105,35 +101,15 @@ Typo3_Bootstrap::getInstance()
        ->initializeTypo3DbGlobal(FALSE)
        ->checkLockedBackendAndRedirectOrDie()
        ->checkBackendIpOrDie()
-       ->checkSslBackendAndRedirectIfNeeded();
-
-       // Connect to the database
-       // Redirect to install tool if database host and database are not defined
-if (!TYPO3_db_host && !TYPO3_db) {
-       t3lib_utility_Http::redirect('install/index.php?mode=123&step=1&password=joh316');
-} else {
-       $TYPO3_DB->connectDB();
-}
-
-       // Checks for proper browser
-if (!$CLIENT['BROWSER']) {
-       throw new RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
-}
-
-Typo3_Bootstrap::getInstance()
+       ->checkSslBackendAndRedirectIfNeeded()
+       ->redirectToInstallToolIfDatabaseCredentialsAreMissing()
+       ->checkValidBrowserOrDie()
+       ->establishDatabaseConnection()
        ->loadExtensionTables()
        ->initializeSpriteManager(TRUE)
        ->initializeBackendUser()
        ->initializeBackendUserMounts()
-       ->initializeLanguageObject();
-
-       // Compression
-ob_clean();
-if (extension_loaded('zlib') && $TYPO3_CONF_VARS['BE']['compressionLevel']) {
-       if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['BE']['compressionLevel'])) {
-               @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['BE']['compressionLevel']);
-       }
-       ob_start('ob_gzhandler');
-}
-
+       ->initializeLanguageObject()
+       ->endOutputBufferingAndCleanPreviousOutput()
+       ->initializeOutputCompression();
 ?>
\ No newline at end of file