Page MenuHomePhabricator

Don't pass Config object to service constructors
Open, Needs TriagePublic

Description

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

daniel created this task.May 22 2019, 6:12 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 22 2019, 6:12 PM

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

https://gerrit.wikimedia.org/r/511937

daniel updated the task description. (Show Details)May 22 2019, 6:22 PM

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

https://gerrit.wikimedia.org/r/511937