Page MenuHomePhabricator

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


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

SamanthaNguyen updated the task description. (Show Details)
SamanthaNguyen moved this task from Incoming / Backlog to Code hygiene on the Cosmos board.

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

SamanthaNguyen triaged this task as Low priority.Oct 17 2020, 4:16 PM