|
1
|
|
|
<?php |
|
2
|
|
|
namespace MediaWiki; |
|
3
|
|
|
|
|
4
|
|
|
use ConfigFactory; |
|
5
|
|
|
use GlobalVarConfig; |
|
6
|
|
|
use Config; |
|
7
|
|
|
use Hooks; |
|
8
|
|
|
use LBFactory; |
|
9
|
|
|
use Liuggio\StatsdClient\Factory\StatsdDataFactory; |
|
10
|
|
|
use LoadBalancer; |
|
11
|
|
|
use MediaWiki\Services\ServiceContainer; |
|
12
|
|
|
use SiteLookup; |
|
13
|
|
|
use SiteStore; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Service locator for MediaWiki core services. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
19
|
|
|
* it under the terms of the GNU General Public License as published by |
|
20
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
21
|
|
|
* (at your option) any later version. |
|
22
|
|
|
* |
|
23
|
|
|
* This program is distributed in the hope that it will be useful, |
|
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26
|
|
|
* GNU General Public License for more details. |
|
27
|
|
|
* |
|
28
|
|
|
* You should have received a copy of the GNU General Public License along |
|
29
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
30
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
31
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
|
32
|
|
|
* |
|
33
|
|
|
* @file |
|
34
|
|
|
* |
|
35
|
|
|
* @since 1.27 |
|
36
|
|
|
*/ |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* MediaWikiServices is the service locator for the application scope of MediaWiki. |
|
40
|
|
|
* Its implemented as a simple configurable DI container. |
|
41
|
|
|
* MediaWikiServices acts as a top level factory/registry for top level services, and builds |
|
42
|
|
|
* the network of service objects that defines MediaWiki's application logic. |
|
43
|
|
|
* It acts as an entry point to MediaWiki's dependency injection mechanism. |
|
44
|
|
|
* |
|
45
|
|
|
* Services are defined in the "wiring" array passed to the constructor, |
|
46
|
|
|
* or by calling defineService(). |
|
47
|
|
|
* |
|
48
|
|
|
* @see docs/injection.txt for an overview of using dependency injection in the |
|
49
|
|
|
* MediaWiki code base. |
|
50
|
|
|
*/ |
|
51
|
|
|
class MediaWikiServices extends ServiceContainer { |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns the global default instance of the top level service locator. |
|
55
|
|
|
* |
|
56
|
|
|
* The default instance is initialized using the service instantiator functions |
|
57
|
|
|
* defined in ServiceWiring.php. |
|
58
|
|
|
* |
|
59
|
|
|
* @note This should only be called by static functions! The instance returned here |
|
60
|
|
|
* should not be passed around! Objects that need access to a service should have |
|
61
|
|
|
* that service injected into the constructor, never a service locator! |
|
62
|
|
|
* |
|
63
|
|
|
* @return MediaWikiServices |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function getInstance() { |
|
66
|
|
|
static $instance = null; |
|
67
|
|
|
|
|
68
|
|
|
if ( $instance === null ) { |
|
69
|
|
|
// NOTE: constructing GlobalVarConfig here is not particularly pretty, |
|
70
|
|
|
// but some information from the global scope has to be injected here, |
|
71
|
|
|
// even if it's just a file name or database credentials to load |
|
72
|
|
|
// configuration from. |
|
73
|
|
|
$config = new GlobalVarConfig(); |
|
74
|
|
|
$instance = new self( $config ); |
|
75
|
|
|
|
|
76
|
|
|
// Load the default wiring from the specified files. |
|
77
|
|
|
$wiringFiles = $config->get( 'ServiceWiringFiles' ); |
|
78
|
|
|
$instance->loadWiringFiles( $wiringFiles ); |
|
79
|
|
|
|
|
80
|
|
|
// Provide a traditional hook point to allow extensions to configure services. |
|
81
|
|
|
Hooks::run( 'MediaWikiServices', [ $instance ] ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $instance; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param Config $config The Config object to be registered as the 'BootstrapConfig' service. |
|
89
|
|
|
* This has to contain at least the information needed to set up the 'ConfigFactory' |
|
90
|
|
|
* service. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function __construct( Config $config ) { |
|
93
|
|
|
parent::__construct(); |
|
94
|
|
|
|
|
95
|
|
|
// register the given Config object as the bootstrap config service. |
|
96
|
|
|
$this->defineService( 'BootstrapConfig', function() use ( $config ) { |
|
97
|
|
|
return $config; |
|
98
|
|
|
} ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Returns the Config object containing the bootstrap configuration. |
|
103
|
|
|
* Bootstrap configuration would typically include database credentials |
|
104
|
|
|
* and other information that may be needed before the ConfigFactory |
|
105
|
|
|
* service can be instantiated. |
|
106
|
|
|
* |
|
107
|
|
|
* @note This should only be used during bootstrapping, in particular |
|
108
|
|
|
* when creating the MainConfig service. Application logic should |
|
109
|
|
|
* use getMainConfig() to get a Config instances. |
|
110
|
|
|
* |
|
111
|
|
|
* @return Config |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getBootstrapConfig() { |
|
114
|
|
|
return $this->getService( 'BootstrapConfig' ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return ConfigFactory |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getConfigFactory() { |
|
121
|
|
|
return $this->getService( 'ConfigFactory' ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Returns the Config object that provides configuration for MediaWiki core. |
|
126
|
|
|
* This may or may not be the same object that is returned by getBootstrapConfig(). |
|
127
|
|
|
* |
|
128
|
|
|
* @return Config |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getMainConfig() { |
|
131
|
|
|
return $this->getService( 'MainConfig' ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return SiteLookup |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getSiteLookup() { |
|
138
|
|
|
return $this->getService( 'SiteLookup' ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return SiteStore |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getSiteStore() { |
|
145
|
|
|
return $this->getService( 'SiteStore' ); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return StatsdDataFactory |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getStatsdDataFactory() { |
|
152
|
|
|
return $this->getService( 'StatsdDataFactory' ); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return EventRelayerGroup |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getEventRelayerGroup() { |
|
159
|
|
|
return $this->getService( 'EventRelayerGroup' ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/////////////////////////////////////////////////////////////////////////// |
|
163
|
|
|
// NOTE: When adding a service getter here, don't forget to add a test |
|
164
|
|
|
// case for it in MediaWikiServicesTest::provideGetters() and in |
|
165
|
|
|
// MediaWikiServicesTest::provideGetService()! |
|
166
|
|
|
/////////////////////////////////////////////////////////////////////////// |
|
167
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|