aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/EventRelayerGroup.php18
-rw-r--r--includes/MediaWikiServices.php7
-rw-r--r--includes/ServiceWiring.php4
-rw-r--r--includes/deferred/CdnCacheUpdate.php4
-rw-r--r--includes/objectcache/ObjectCache.php4
-rw-r--r--tests/phpunit/includes/MediaWikiServicesTest.php2
6 files changed, 26 insertions, 13 deletions
diff --git a/includes/EventRelayerGroup.php b/includes/EventRelayerGroup.php
index 9dfac795a6a4..9360693a4b8e 100644
--- a/includes/EventRelayerGroup.php
+++ b/includes/EventRelayerGroup.php
@@ -1,4 +1,6 @@
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Factory class for spawning EventRelayer objects using configuration
*
@@ -12,25 +14,19 @@ class EventRelayerGroup {
/** @var EventRelayer[] */
protected $relayers = [];
- /** @var EventRelayerGroup */
- protected static $instance = null;
-
/**
- * @param Config $config
+ * @param array[] $config Channel configuration
*/
- protected function __construct( Config $config ) {
- $this->configByChannel = $config->get( 'EventRelayerConfig' );
+ public function __construct( array $config ) {
+ $this->configByChannel = $config;
}
/**
+ * @deprecated since 1.27 Use MediaWikiServices::getInstance()->getEventRelayerGroup()
* @return EventRelayerGroup
*/
public static function singleton() {
- if ( !self::$instance ) {
- self::$instance = new self( RequestContext::getMain()->getConfig() );
- }
-
- return self::$instance;
+ return MediaWikiServices::getInstance()->getEventRelayerGroup();
}
/**
diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php
index 3f4d8ed7c783..9a942a55d020 100644
--- a/includes/MediaWikiServices.php
+++ b/includes/MediaWikiServices.php
@@ -152,6 +152,13 @@ class MediaWikiServices extends ServiceContainer {
return $this->getService( 'StatsdDataFactory' );
}
+ /**
+ * @return EventRelayerGroup
+ */
+ public function getEventRelayerGroup() {
+ return $this->getService( 'EventRelayerGroup' );
+ }
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service getter here, don't forget to add a test
// case for it in MediaWikiServicesTest::provideGetters() and in
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 7e1d4e314e1a..991a67d73788 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -78,6 +78,10 @@ return [
);
},
+ 'EventRelayerGroup' => function( MediaWikiServices $services ) {
+ return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
+ },
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service here, don't forget to add a getter function
// in the MediaWikiServices class. The convenience getter should just call
diff --git a/includes/deferred/CdnCacheUpdate.php b/includes/deferred/CdnCacheUpdate.php
index 32f6adc6420e..65ff9f307de6 100644
--- a/includes/deferred/CdnCacheUpdate.php
+++ b/includes/deferred/CdnCacheUpdate.php
@@ -22,6 +22,7 @@
*/
use Wikimedia\Assert\Assert;
+use MediaWiki\MediaWikiServices;
/**
* Handles purging appropriate CDN URLs given a title (or titles)
@@ -109,7 +110,8 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
wfDebugLog( 'squid', __METHOD__ . ': ' . implode( ' ', $urlArr ) );
// Reliably broadcast the purge to all edge nodes
- $relayer = EventRelayerGroup::singleton()->getRelayer( 'cdn-url-purges' );
+ $relayer = MediaWikiServices::getInstance()->getEventRelayerGroup()
+ ->getRelayer( 'cdn-url-purges' );
$relayer->notify(
'cdn-url-purges',
[
diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php
index e9f2211aaf18..24846e6ed697 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -22,6 +22,7 @@
*/
use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
/**
* Functions to get cache objects
@@ -299,7 +300,8 @@ class ObjectCache {
$params = $wgWANObjectCaches[$id];
foreach ( $params['channels'] as $action => $channel ) {
- $params['relayers'][$action] = EventRelayerGroup::singleton()->getRelayer( $channel );
+ $params['relayers'][$action] = MediaWikiServices::getInstance()->getEventRelayerGroup()
+ ->getRelayer( $channel );
$params['channels'][$action] = $channel;
}
$params['cache'] = self::newFromId( $params['cacheId'] );
diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php
index 188957569bf5..a89bd909313c 100644
--- a/tests/phpunit/includes/MediaWikiServicesTest.php
+++ b/tests/phpunit/includes/MediaWikiServicesTest.php
@@ -25,6 +25,7 @@ class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
'SiteStore' => [ 'getSiteStore', SiteStore::class ],
'SiteLookup' => [ 'getSiteLookup', SiteLookup::class ],
'StatsdDataFactory' => [ 'getStatsdDataFactory', StatsdDataFactory::class ],
+ 'EventRelayerGroup' => [ 'getEventRelayerGroup', EventRelayerGroup::class ],
];
}
@@ -49,6 +50,7 @@ class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
'SiteStore' => [ 'SiteStore', SiteStore::class ],
'SiteLookup' => [ 'SiteLookup', SiteLookup::class ],
'StatsdDataFactory' => [ 'StatsdDataFactory', StatsdDataFactory::class ],
+ 'EventRelayerGroup' => [ 'EventRelayerGroup', EventRelayerGroup::class ],
];
}