I'm catching up on MediaWiki core changes, and saw the introduction of the ServiceOptions class, which I think is alright, but could be better. I believe I read through all of the discussion on the Gerrit change, but it's possible I missed something.
- I think it's awkward that MainConfig gets passed to the ServiceOptions constructor. I think this is backwards in that we don't want ServiceOptions and the service itself to know of all the options.
- ServiceOptions implements basically the \Config interface, except it doesn't.
- As explained on T224165, tests have to go through $this->overrideMwServices( new HashConfig( [ 'Sitename' => 'TestMediaWiki' ] ) ); instead of passing the Config object directly.
- The key list is needed twice, in the builder and in the constructor. I don't have any suggestions on how to fix this though.
Add a Config::withSubset( Class::CONSTUCTOR_OPTIONS ) that returns a Config implementation (either HashConfig or a new FrozenConfig, which is Hash without the mutability) with only the necessary keys. This allows us to continue relying on the Config interface, making it convenient for adhoc usage and tests. Also, the class is only ever aware of the config options it wants, not extra things.
I note that ServiceOptions allows adding from an arbitrary number of Config classes/arrays, it wasn't clear to me though exactly how important that use case was.