Move service option keys to CONSTRUCTOR_OPTIONS

Why:
* The standard format for ServiceOption keys is to provide them
  in a const named CONSTRUCTOR_OPTIONS.
* Doing this makes it possible to assert that the required keys
  are in the ServiceOptions instance passed in the constructor
  (as it may be called directly without using ::factory).

What:
* Move the ServiceOptions keys to a CONSTRUCTOR_OPTIONS const in
  Hooks.php
* Reference this constant in the ::factory and ::__construct
  methods.

Change-Id: Icba2eadc9faf4a15abf4d52efa541e5ddb0294bd
这个提交包含在:
Dreamy Jazz 2024-05-04 20:22:14 +03:00 提交者 Dreamy Jazz
父节点 94be0327e4
当前提交 47bba9d407
共有 1 个文件被更改,包括 11 次插入14 次删除

查看文件

@ -51,11 +51,16 @@ class Hooks implements
UploadForm_initialHook
{
/** @var ExtensionRegistry */
private $extensionRegistry;
public const CONSTRUCTOR_OPTIONS = [
MainConfigNames::DBname,
MainConfigNames::ForceUIMsgAsContentMsg,
'WikimediaMessagesLicensing',
MainConfigNames::LanguageCode,
MainConfigNames::RightsText,
];
/** @var ServiceOptions */
private $options;
private ExtensionRegistry $extensionRegistry;
private ServiceOptions $options;
/**
* @param ExtensionRegistry $extensionRegistry
@ -65,6 +70,7 @@ class Hooks implements
ExtensionRegistry $extensionRegistry,
ServiceOptions $options
) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->extensionRegistry = $extensionRegistry;
$this->options = $options;
}
@ -77,16 +83,7 @@ class Hooks implements
public static function factory( Config $mainConfig ): Hooks {
return new self(
ExtensionRegistry::getInstance(),
new ServiceOptions(
[
MainConfigNames::DBname,
MainConfigNames::ForceUIMsgAsContentMsg,
'WikimediaMessagesLicensing',
MainConfigNames::LanguageCode,
MainConfigNames::RightsText,
],
$mainConfig
)
new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $mainConfig )
);
}