Page MenuHomePhabricator

Don't pass Config object to service constructors
Closed, ResolvedPublic


Services should not depend on the entire site configuration when they only need a few specific settings.

To avoid this, a ServiceOptions class should be created that is similar to the Config class, but designed to only hold a specific set of options, and provides utility methods for ensuring the required set of option was passed. In a way, this just works around PHP's lack of named parameters.

This change means that these services no longer see a live version of the settings in global variables, but get a copy when they are created. This means in tests you have to call overrideMwServices() if you want services to pick up your config changes, e.g.

$this->overrideMwServices( new HashConfig( [ 'Sitename' => 'TestMediaWiki' ] ) );
NOTE: This ticket was filed retroactively for reference. ServiceOptions was implemented in I1a3f358e8659b.

Event Timeline

Change 511937 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] Reference T224165 when deprecating Parser::$mConf

Change 511937 merged by jenkins-bot:
[mediawiki/core@master] Reference T224165 when deprecating Parser::$mConf