Page MenuHomePhabricator

Cosmos skin: Create high-level abstraction layer that can validate and retrieve configuration settings
Closed, ResolvedPublic


Copied from comment on, 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):

The code block included:


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...

Event Timeline

Before this is done, needs some reviewing of how we can make it work nicely with \ServiceOptions, eventually we'll want to convert some stuff into services

Change 657112 had a related patch set uploaded (by Universal Omega; owner: Universal Omega):
[mediawiki/skins/Cosmos@master] [Cosmos] Create new CosmosConfig service to later validate configuration settings

Change 657112 merged by jenkins-bot:
[mediawiki/skins/Cosmos@master] [Cosmos] Create new CosmosConfig service to later validate configuration settings

Universal_Omega removed a project: Patch-For-Review.
Universal_Omega moved this task from In Progress to Done on the Cosmos board.