Move PSR-3 support check right after autoloader setup
authorGergő Tisza <tgr.huwiki@gmail.com>
Mon, 26 Oct 2015 02:00:24 +0000 (19:00 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 14 Dec 2015 06:18:07 +0000 (22:18 -0800)
This ensures that, in case "composer install" has not been run,
the user will see the error message about setting up dependencies
(as opposed a plain "Class not found" error because some other
dependency was used first).

Change-Id: Ib6026123770d21cc9f8960a1de361c8178b1b044

includes/WebStart.php
includes/debug/logger/LoggerFactory.php

index adce346..82d3955 100644 (file)
@@ -103,6 +103,21 @@ if ( is_readable( "$IP/vendor/autoload.php" ) ) {
        require_once "$IP/vendor/autoload.php";
 }
 
+# assert that composer dependencies were successfully loaded
+if ( !interface_exists( '\Psr\Log\LoggerInterface' ) ) {
+       $message = (
+               'MediaWiki requires the <a href="https://github.com/php-fig/log">PSR-3 logging ' .
+               "library</a> to be present. This library is not embedded directly in MediaWiki's " .
+               "git repository and must be installed separately by the end user.\n\n" .
+               'Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
+               '#Fetch_external_libraries">mediawiki.org</a> for help on installing ' .
+               'the required components.'
+       );
+       echo $message;
+       trigger_error( $message, E_USER_ERROR );
+       die( 1 );
+}
+
 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
        # Use a callback function to configure MediaWiki
        call_user_func( MW_CONFIG_CALLBACK );
index b0a10ce..e0c4989 100644 (file)
@@ -94,24 +94,6 @@ class LoggerFactory {
         * @return \Psr\Log\LoggerInterface
         */
        public static function getInstance( $channel ) {
-               static $hasPSR3Interface = null;
-               if ( $hasPSR3Interface === null ) {
-                       $hasPSR3Interface = interface_exists( 'Psr\Log\LoggerInterface' );
-                       if ( !$hasPSR3Interface ) {
-                               $message = (
-                                       'MediaWiki requires the <a href="https://github.com/php-fig/log">PSR-3 logging ' .
-                                       "library</a> to be present. This library is not embedded directly in MediaWiki's " .
-                                       "git repository and must be installed separately by the end user.\n\n" .
-                                       'Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
-                                       '#Fetch_external_libraries">mediawiki.org</a> for help on installing ' .
-                                       'the required components.'
-                               );
-                               echo $message;
-                               trigger_error( $message, E_USER_ERROR );
-                               die( 1 );
-                       }
-               }
-
                return self::getProvider()->getLogger( $channel );
        }