mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-12 07:55:53 +00:00
ef50bfeda5
Singletons are bad, amongst other reasons, because they're never reset in tests. They can therefore occasionally cause test failures if the cached data stored in one of these singletons becomes stale. As noted on the task, ideally these two classes shouldn't exist at all, and core should be responsible for caching the information it deems expensive to compute. As a temporary (TM) workaround, make both classes actual services, so that the setUp/tearDown logic in MediaWikiIntegrationTestCase can properly reset them between tests. Dependencies are intentionally not being injected, precisely because these classes should just be deleted, not improved. Bug: T344124 Change-Id: I58b8d9610f9447468235b94d25732528ab6acce6
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Notifications\Cache\RevisionLocalCache;
|
|
use MediaWiki\Extension\Notifications\Cache\TitleLocalCache;
|
|
use MediaWiki\Extension\Notifications\Push\NotificationServiceClient;
|
|
use MediaWiki\Extension\Notifications\Push\SubscriptionManager;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
class EchoServices {
|
|
|
|
/** @var MediaWikiServices */
|
|
private $services;
|
|
|
|
/** @return EchoServices */
|
|
public static function getInstance(): EchoServices {
|
|
return new self( MediaWikiServices::getInstance() );
|
|
}
|
|
|
|
/**
|
|
* @param MediaWikiServices $services
|
|
* @return EchoServices
|
|
*/
|
|
public static function wrap( MediaWikiServices $services ): EchoServices {
|
|
return new self( $services );
|
|
}
|
|
|
|
/** @param MediaWikiServices $services */
|
|
public function __construct( MediaWikiServices $services ) {
|
|
$this->services = $services;
|
|
}
|
|
|
|
/** @return NotificationServiceClient */
|
|
public function getPushNotificationServiceClient(): NotificationServiceClient {
|
|
return $this->services->getService( 'EchoPushNotificationServiceClient' );
|
|
}
|
|
|
|
/** @return SubscriptionManager */
|
|
public function getPushSubscriptionManager(): SubscriptionManager {
|
|
return $this->services->getService( 'EchoPushSubscriptionManager' );
|
|
}
|
|
|
|
/** @return EchoAttributeManager */
|
|
public function getAttributeManager(): EchoAttributeManager {
|
|
return $this->services->getService( 'EchoAttributeManager' );
|
|
}
|
|
|
|
/** @return TitleLocalCache */
|
|
public function getTitleLocalCache(): TitleLocalCache {
|
|
return $this->services->getService( 'EchoTitleLocalCache' );
|
|
}
|
|
|
|
/** @return RevisionLocalCache */
|
|
public function getRevisionLocalCache(): RevisionLocalCache {
|
|
return $this->services->getService( 'EchoRevisionLocalCache' );
|
|
}
|
|
}
|