From ae944fc38b169b4dcde3cd14341a17d21f463116 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 14 Feb 2023 21:06:17 +0000 Subject: ObjectCache: Make newFromParams() more suitable for internal re-use I added the `Config` parameter not so long ago, but this still seems awkward and insufficient. Instead of requiring the caller in ServiceWiring to unpack each service, do this here instead to better separate the concerns between what a service owner should know vs what maintainers of ObjectCache need to know. Document the parameter as internal going forward. There exist no callers Codesearch Everywhere outside these two core files. Bug: T329680 Change-Id: I37e3fcae0551ba96d480071b2da5166ac966092e --- includes/objectcache/ObjectCache.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'includes/objectcache/ObjectCache.php') diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 152e3c190f98..b9beeb54f959 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -133,11 +133,13 @@ class ObjectCache { * - class: BagOStuff subclass constructed with $params. * - loggroup: Alias to set 'logger' key with LoggerFactory group. * - .. Other parameters passed to factory or class. - * @param Config|null $conf (Since 1.35) + * @param MediaWikiServices|null $services [internal] * @return BagOStuff */ - public static function newFromParams( array $params, Config $conf = null ) { - $services = MediaWikiServices::getInstance(); + public static function newFromParams( array $params, MediaWikiServices $services = null ) { + $services ??= MediaWikiServices::getInstance(); + $conf = $services->getMainConfig(); + // Apply default parameters and resolve the logger instance $params += [ 'logger' => LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' ), @@ -160,7 +162,6 @@ class ObjectCache { } $class = $params['class']; - $conf ??= $services->getMainConfig(); // Normalization and DI for SqlBagOStuff if ( is_a( $class, SqlBagOStuff::class, true ) ) { @@ -211,7 +212,7 @@ class ObjectCache { foreach ( $params['caches'] ?? [] as $i => $cacheInfo ) { // Ensure logger, keyspace, asyncHandler, etc are injected just as if // one of these was configured without MultiWriteBagOStuff. - $params['caches'][$i] = self::newFromParams( $cacheInfo, $conf ); + $params['caches'][$i] = self::newFromParams( $cacheInfo, $services ); } } -- cgit v1.2.3