Merge "Make the global objects documentation consistent in Setup.php"
[lhc/web/wiklou.git] / includes / context / RequestContext.php
index 93602a0..d4bf0b4 100644 (file)
@@ -68,6 +68,11 @@ class RequestContext implements IContextSource {
         */
        private $config;
 
+       /**
+        * @var RequestContext
+        */
+       private static $instance = null;
+
        /**
         * Set the Config object
         *
@@ -411,12 +416,21 @@ class RequestContext implements IContextSource {
         * @return RequestContext
         */
        public static function getMain() {
-               static $instance = null;
-               if ( $instance === null ) {
-                       $instance = new self;
+               if ( self::$instance === null ) {
+                       self::$instance = new self;
                }
 
-               return $instance;
+               return self::$instance;
+       }
+
+       /**
+        * Resets singleton returned by getMain(). Should be called only from unit tests.
+        */
+       public static function resetMain() {
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+                       throw new MWException( __METHOD__ . '() should be called only from unit tests!' );
+               }
+               self::$instance = null;
        }
 
        /**