3 * Default wiring for MediaWiki services.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 * This file is loaded by MediaWiki\MediaWikiServices::getInstance() during the
23 * bootstrapping of the dependency injection framework.
25 * This file returns an array that associates service name with instantiator functions
26 * that create the default instances for the services used by MediaWiki core.
27 * For every service that MediaWiki core requires, an instantiator must be defined in
30 * @note As of version 1.27, MediaWiki is only beginning to use dependency injection.
31 * The services defined here do not yet fully represent all services used by core,
32 * much of the code still relies on global state for this accessing services.
36 * @see docs/injection.txt for an overview of using dependency injection in the
37 * MediaWiki code base.
40 use MediaWiki\MediaWikiServices
;
43 'SiteStore' => function( MediaWikiServices
$services ) {
44 $loadBalancer = wfGetLB(); // TODO: use LB from MediaWikiServices
45 $rawSiteStore = new DBSiteStore( $loadBalancer );
47 // TODO: replace wfGetCache with a CacheFactory service.
48 // TODO: replace wfIsHHVM with a capabilities service.
49 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL
: CACHE_ANYTHING
);
51 return new CachingSiteStore( $rawSiteStore, $cache );
54 'SiteLookup' => function( MediaWikiServices
$services ) {
55 // Use the default SiteStore as the SiteLookup implementation for now
56 return $services->getSiteStore();
59 'ConfigFactory' => function( MediaWikiServices
$services ) {
60 // Use the bootstrap config to initialize the ConfigFactory.
61 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
62 $factory = new ConfigFactory();
64 foreach ( $registry as $name => $callback ) {
65 $factory->register( $name, $callback );
70 'MainConfig' => function( MediaWikiServices
$services ) {
71 // Use the 'main' config from the ConfigFactory service.
72 return $services->getConfigFactory()->makeConfig( 'main' );
75 ///////////////////////////////////////////////////////////////////////////
76 // NOTE: When adding a service here, don't forget to add a getter function
77 // in the MediaWikiServices class. The convenience getter should just call
78 // $this->getService( 'FooBarService' ).
79 ///////////////////////////////////////////////////////////////////////////