Make abstract Config class truly implementation-agnostic
authorKunal Mehta <legoktm@gmail.com>
Sat, 10 May 2014 08:19:00 +0000 (01:19 -0700)
committerKunal Mehta <legoktm@gmail.com>
Mon, 26 May 2014 09:59:57 +0000 (02:59 -0700)
commit8977e56a6b71e10e6046537cd82a3e32aea12f86
tree71d2f393e90056498eab291c7fb52b2f4d71fdb0
parentfef5c1891a6d3164f78e9c68bd0908f92b3b5778
Make abstract Config class truly implementation-agnostic

Follow up to I13baec0b6 ("Config: Add Config and GlobalConfig classes"):

Config:
* Rather than returning Status objects, Config::set will now throw an exception
  if an error is encountered
* Config::factory was moved into it's own ConfigFactory class.
* Since there are no more functions in it, Config was turned into an interface.

GlobalConfig:
* Remove $prefix args from Config::set and ::get. The idea of having an
  abstract Config class is to abstract some notion of configuration data from
  the particular way in which it is currently implemented (global variables).
  So the abstract base class has no business dealing with variable name
  prefixes.
** Instead GlobalVarConfig's implementations of get and set call getWithPrefix
   and setWithPrefix internally, which are now protected
* Rename GlobalConfig to GlobalVarConfig, which makes it clearer that it isn't
  referring to the scope of the configuration value, but to the scope of the
  variable name which provides it.

ConfigFactory:
* ConfigFactory is where Config objects are registered, and later constructed.
* Config objects are registered with a given name, and a callback factory function.
  This allows for implementations to construct the object with the parameters they want,
  and avoids the overhead of needing an entire class.
** The name 'main' is the default object returned by RequestContext::getConfig(),
   and is intended to be used by core.
* This is a singleton class, the main instance can be obtained with:
  ConfigFactory::getDefaultInstance()

In addition to the above:
* $wgConfigClass was removed, and $wgConfigRegistry was introduced, which
  stores a name => callback. The name is to be what the Config instance is
  registered with, and the callback should return an implementation of Config.
* Tests were written for the new ConfigFactory, and GlobalVarConfig's tests
  were improved.

Co-Authored-By: Ori Livneh <ori@wikimedia.org>
Co-Authored-By: Chad Horohoe <chadh@wikimedia.org>
Co-Authored-By: Mattflaschen <mflaschen@wikimedia.org>
Co-Authored-By: Parent5446 <tylerromeo@gmail.com>
Co-Authored-By: Reedy <reedy@wikimedia.org>
Co-Authored-By: Daniel Kinzler <daniel.kinzler@wikimedia.de>
Change-Id: I5a5857fcfa07598ba4ce9ae5bbb4ce54a567d31e
includes/AutoLoader.php
includes/DefaultSettings.php
includes/config/Config.php
includes/config/ConfigException.php [new file with mode: 0644]
includes/config/ConfigFactory.php [new file with mode: 0644]
includes/config/GlobalConfig.php [deleted file]
includes/config/GlobalVarConfig.php [new file with mode: 0644]
includes/context/RequestContext.php
tests/phpunit/includes/config/ConfigFactoryTest.php [new file with mode: 0644]
tests/phpunit/includes/config/GlobalConfigTest.php [deleted file]
tests/phpunit/includes/config/GlobalVarConfigTest.php [new file with mode: 0644]