MediaWiki  1.27.2
MediaWikiServices.php
Go to the documentation of this file.
1 <?php
2 namespace MediaWiki;
3 
7 use Config;
8 use Hooks;
17 
54 class MediaWikiServices extends ServiceContainer {
55 
68  public static function getInstance() {
69  static $instance = null;
70 
71  if ( $instance === null ) {
72  // NOTE: constructing GlobalVarConfig here is not particularly pretty,
73  // but some information from the global scope has to be injected here,
74  // even if it's just a file name or database credentials to load
75  // configuration from.
76  $config = new GlobalVarConfig();
77  $instance = new self( $config );
78 
79  // Load the default wiring from the specified files.
80  $wiringFiles = $config->get( 'ServiceWiringFiles' );
81  $instance->loadWiringFiles( $wiringFiles );
82 
83  // Provide a traditional hook point to allow extensions to configure services.
84  Hooks::run( 'MediaWikiServices', [ $instance ] );
85  }
86 
87  return $instance;
88  }
89 
95  public function __construct( Config $config ) {
96  parent::__construct();
97 
98  // register the given Config object as the bootstrap config service.
99  $this->defineService( 'BootstrapConfig', function() use ( $config ) {
100  return $config;
101  } );
102  }
103 
116  public function getBootstrapConfig() {
117  return $this->getService( 'BootstrapConfig' );
118  }
119 
123  public function getConfigFactory() {
124  return $this->getService( 'ConfigFactory' );
125  }
126 
133  public function getMainConfig() {
134  return $this->getService( 'MainConfig' );
135  }
136 
140  public function getSiteLookup() {
141  return $this->getService( 'SiteLookup' );
142  }
143 
147  public function getSiteStore() {
148  return $this->getService( 'SiteStore' );
149  }
150 
154  public function getStatsdDataFactory() {
155  return $this->getService( 'StatsdDataFactory' );
156  }
157 
161  public function getEventRelayerGroup() {
162  return $this->getService( 'EventRelayerGroup' );
163  }
164 
168  public function newSearchEngine() {
169  // New engine object every time, since they keep state
170  return $this->getService( 'SearchEngineFactory' )->create();
171  }
172 
176  public function getSearchEngineFactory() {
177  return $this->getService( 'SearchEngineFactory' );
178  }
179 
183  public function getSearchEngineConfig() {
184  return $this->getService( 'SearchEngineConfig' );
185  }
186 
190  public function getSkinFactory() {
191  return $this->getService( 'SkinFactory' );
192  }
193 
195  // NOTE: When adding a service getter here, don't forget to add a test
196  // case for it in MediaWikiServicesTest::provideGetters() and in
197  // MediaWikiServicesTest::provideGetService()!
199 
200 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
A helper class for throttling authentication attempts.
static getInstance()
Returns the global default instance of the top level service locator.
getMainConfig()
Returns the Config object that provides configuration for MediaWiki core.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
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
Definition: injection.txt:35
getBootstrapConfig()
Returns the Config object containing the bootstrap configuration.
MediaWikiServices is the service locator for the application scope of MediaWiki.