Esempio n. 1
0
 /**
  * Creates a new instance of MediaWikiServices and sets it as the global default
  * instance. getInstance() will return a different MediaWikiServices object
  * after every call to resetGlobalInstance().
  *
  * @since 1.28
  *
  * @warning This should not be used during normal operation. It is intended for use
  * when the configuration has changed significantly since bootstrap time, e.g.
  * during the installation process or during testing.
  *
  * @warning Calling resetGlobalInstance() may leave the application in an inconsistent
  * state. Calling this is only safe under the ASSUMPTION that NO REFERENCE to
  * any of the services managed by MediaWikiServices exist. If any service objects
  * managed by the old MediaWikiServices instance remain in use, they may INTERFERE
  * with the operation of the services managed by the new MediaWikiServices.
  * Operating with a mix of services created by the old and the new
  * MediaWikiServices instance may lead to INCONSISTENCIES and even DATA LOSS!
  * Any class implementing LAZY LOADING is especially prone to this problem,
  * since instances would typically retain a reference to a storage layer service.
  *
  * @see forceGlobalInstance()
  * @see resetGlobalInstance()
  * @see resetBetweenTest()
  *
  * @param Config|null $bootstrapConfig The Config object to be registered as the
  *        'BootstrapConfig' service. This has to contain at least the information
  *        needed to set up the 'ConfigFactory' service. If not given, the bootstrap
  *        config of the old instance of MediaWikiServices will be re-used. If there
  *        was no previous instance, a new GlobalVarConfig object will be used to
  *        bootstrap the services.
  *
  * @param string $quick Set this to "quick" to allow expensive resources to be re-used.
  * See SalvageableService for details.
  *
  * @throws MWException If called after MW_SERVICE_BOOTSTRAP_COMPLETE has been defined in
  *         Setup.php (unless MW_PHPUNIT_TEST or MEDIAWIKI_INSTALL or RUN_MAINTENANCE_IF_MAIN
  *          is defined).
  */
 public static function resetGlobalInstance(Config $bootstrapConfig = null, $quick = '')
 {
     if (self::$instance === null) {
         // no global instance yet, nothing to reset
         return;
     }
     self::failIfResetNotAllowed(__METHOD__);
     if ($bootstrapConfig === null) {
         $bootstrapConfig = self::$instance->getBootstrapConfig();
     }
     $oldInstance = self::$instance;
     self::$instance = self::newInstance($bootstrapConfig, 'load');
     self::$instance->importWiring($oldInstance, ['BootstrapConfig']);
     if ($quick === 'quick') {
         self::$instance->salvage($oldInstance);
     } else {
         $oldInstance->destroy();
     }
 }