From: Aaron Schulz Date: Thu, 1 Aug 2019 18:54:30 +0000 (-0400) Subject: Code style cleanups to FileBackendGroup X-Git-Tag: 1.34.0-rc.0~786^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=69f50aaceae26ec3d74ba448873803a14bf46849;p=lhc%2Fweb%2Fwiklou.git Code style cleanups to FileBackendGroup Set domainId in register() instead of on every config() call. Use array_merge() to make the override precedence clearer. Change-Id: I8792281cd9f1a4018255f9a9b87126c909095e68 --- diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index a5860e2571..7ec2357e5b 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -117,12 +117,14 @@ class FileBackendGroup { } $name = $config['name']; if ( isset( $this->backends[$name] ) ) { - throw new LogicException( "Backend with name `{$name}` already registered." ); + throw new LogicException( "Backend with name '$name' already registered." ); } elseif ( !isset( $config['class'] ) ) { - throw new InvalidArgumentException( "Backend with name `{$name}` has no class." ); + throw new InvalidArgumentException( "Backend with name '$name' has no class." ); } $class = $config['class']; + // @FIXME: ideally this would default to the DB domain (which includes the schema) + $config['domainId'] = $config['domainId'] ?? ( $config['wikiId'] ?? wfWikiID() ); $config['readOnly'] = $config['readOnly'] ?? $readOnlyReason; unset( $config['class'] ); // backend won't need this @@ -172,40 +174,40 @@ class FileBackendGroup { */ public function config( $name ) { if ( !isset( $this->backends[$name] ) ) { - throw new InvalidArgumentException( "No backend defined with the name `$name`." ); + throw new InvalidArgumentException( "No backend defined with the name '$name'." ); } - $class = $this->backends[$name]['class']; $config = $this->backends[$name]['config']; - $config['class'] = $class; - if ( isset( $config['domainId'] ) ) { - $domain = $config['domainId']; - } else { - // @FIXME: this does not include the domain for b/c but it ideally should - $domain = $config['wikiId'] ?? wfWikiID(); - } - // Set default parameter values - $config += [ - 'domainId' => $domain, // e.g. "my_wiki-en_" - 'mimeCallback' => [ $this, 'guessMimeInternal' ], - 'obResetFunc' => 'wfResetOutputBuffers', - 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], - 'tmpDirectory' => wfTempDir(), - 'statusWrapper' => [ Status::class, 'wrap' ], - 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), - 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), - 'logger' => LoggerFactory::getInstance( 'FileOperation' ), - 'profiler' => function ( $section ) { - return Profiler::instance()->scopedProfileIn( $section ); - } - ]; - $config['lockManager'] = - LockManagerGroup::singleton( $domain )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ); - - return $config; + $services = MediaWikiServices::getInstance(); + + return array_merge( + // Default backend parameters + [ + 'mimeCallback' => [ $this, 'guessMimeInternal' ], + 'obResetFunc' => 'wfResetOutputBuffers', + 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], + 'tmpDirectory' => wfTempDir(), + 'statusWrapper' => [ Status::class, 'wrap' ], + 'wanCache' => $services->getMainWANObjectCache(), + 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), + 'logger' => LoggerFactory::getInstance( 'FileOperation' ), + 'profiler' => function ( $section ) { + return Profiler::instance()->scopedProfileIn( $section ); + } + ], + // Configured backend parameters + $config, + // Resolved backend parameters + [ + 'class' => $this->backends[$name]['class'], + 'lockManager' => + LockManagerGroup::singleton( $config['domainId'] ) + ->get( $config['lockManager'] ), + 'fileJournal' => isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ) + ] + ); } /**