80 private static $instance = null;
97 if ( self::$instance === null ) {
103 self::$instance = self::newInstance( $bootstrapConfig,
'load' );
106 return self::$instance;
123 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
124 throw new MWException( __METHOD__ .
' must not be used outside unit tests.' );
127 $old = self::getInstance();
173 if ( self::$instance === null ) {
178 self::failIfResetNotAllowed( __METHOD__ );
180 if ( $bootstrapConfig === null ) {
181 $bootstrapConfig = self::$instance->getBootstrapConfig();
184 $oldInstance = self::$instance;
186 self::$instance = self::newInstance( $bootstrapConfig,
'load' );
187 self::$instance->importWiring( $oldInstance, [
'BootstrapConfig' ] );
189 if ( $quick ===
'quick' ) {
190 self::$instance->salvage( $oldInstance );
192 $oldInstance->destroy();
205 foreach ( $this->getServiceNames()
as $name ) {
210 $oldService = $other->peekService( $name );
211 }
catch ( NoSuchServiceException
$e ) {
215 if ( $oldService instanceof SalvageableService ) {
217 $newService = $this->getService( $name );
218 $newService->salvage( $oldService );
241 $instance =
new self( $bootstrapConfig );
244 if ( $loadWiring ===
'load' ) {
245 $wiringFiles = $bootstrapConfig->
get(
'ServiceWiringFiles' );
246 $instance->loadWiringFiles( $wiringFiles );
250 Hooks::run(
'MediaWikiServices', [ $instance ] );
272 $destroy = [
'DBLoadBalancer',
'DBLoadBalancerFactory' ];
275 foreach ( $destroy
as $name ) {
297 self::resetGlobalInstance();
301 mt_srand( getmypid() );
326 if ( !defined(
'MW_PHPUNIT_TEST' ) && !defined(
'MW_PARSER_TEST' ) ) {
327 throw new MWException(
'resetServiceForTesting() must not be used outside unit tests.' );
330 $this->resetService(
$name, $destroy );
361 if ( !defined(
'MW_PHPUNIT_TEST' )
362 && !defined(
'MW_PARSER_TEST' )
363 && !defined(
'MEDIAWIKI_INSTALL' )
364 && !defined(
'RUN_MAINTENANCE_IF_MAIN' )
365 && defined(
'MW_SERVICE_BOOTSTRAP_COMPLETE' )
367 throw new MWException( $method .
' may only be called during bootstrapping and unit tests!' );
377 parent::__construct();
380 $this->defineService(
'BootstrapConfig',
function()
use ( $config ) {
401 return $this->getService(
'BootstrapConfig' );
409 return $this->getService(
'ConfigFactory' );
420 return $this->getService(
'MainConfig' );
428 return $this->getService(
'SiteLookup' );
436 return $this->getService(
'SiteStore' );
444 return $this->getService(
'InterwikiLookup' );
452 return $this->getService(
'StatsdDataFactory' );
460 return $this->getService(
'EventRelayerGroup' );
469 return $this->getService(
'SearchEngineFactory' )->create();
477 return $this->getService(
'SearchEngineFactory' );
485 return $this->getService(
'SearchEngineConfig' );
493 return $this->getService(
'SkinFactory' );
501 return $this->getService(
'DBLoadBalancerFactory' );
509 return $this->getService(
'DBLoadBalancer' );
517 return $this->getService(
'WatchedItemStore' );
525 return $this->getService(
'WatchedItemQueryService' );
533 return $this->getService(
'CryptRand' );
541 return $this->getService(
'CryptHKDF' );
549 return $this->getService(
'MediaHandlerFactory' );
557 return $this->getService(
'MimeAnalyzer' );
565 return $this->getService(
'ProxyLookup' );
573 return $this->getService(
'GenderCache' );
581 return $this->getService(
'LinkCache' );
589 return $this->getService(
'LinkRendererFactory' );
600 return $this->getService(
'LinkRenderer' );
608 return $this->getService(
'TitleFormatter' );
616 return $this->getService(
'TitleParser' );
624 return $this->getService(
'MainObjectStash' );
632 return $this->getService(
'MainWANObjectCache' );
640 return $this->getService(
'LocalServerObjectCache' );
648 return $this->getService(
'VirtualRESTServiceClient' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
get($name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static clear()
Clear all the cached instances.
Allows to change the fields on the form that will be generated $name