Copied from comment on https://gerrit.wikimedia.org/r/c/mediawiki/skins/Cosmos/+/633762, to be done as a follow-up to that patch and to T264907
If there was only a few configuration settings, I probably would not be recommending the following, but as we scale up and add more configuration settings (and especially with how many), I suggest the following as a follow-up:
I suggest we keep the Config abstraction layer, but we do the abstraction layer differently. It should have a \Config object injected, with the class as readonly (just providing get methods). Each method retrieves a configuration setting.
This ensures we will always get it, as it is very easy to make typos in strings, but if we typo'd with a method, a PHP exception will throw instead.
This abstraction layer would allow to centralize the validation of user input of configuration settings, instead of having the user of the API to do their own validation every time. It will also continue to allow to enforce typehinting. This API would be registered as a service (more on that later).
See the gist for the implementation idea of the refactored abstraction layer (which would allow easily setting up validation): https://gist.github.com/neoncitylights/7d3155a9943f50c74fdd6e8777195a0c
The code block included:
<?php namespace MediaWiki\Skins\Cosmos; use Config; class CosmosConfig { /** @var Config */ private $config; public function __construct( Config $config ) { $this->config = $config; } public function getWikiHeaderBackgroundColor() : string { return $this->config->get( 'CosmosWikiHeaderBackgroundColor' ); } // more examples here... }