So I was playing with the idea of a core helper class for accessing config:
https://github.com/aolley/moodle/blob/core_cfg/lib/classes/cfg.php
The idea is that instead of declaring "global $CFG;" and then using the $CFG variable in your code, you could just call:
\core\cfg::core('somesetting')
I also threw some wrappers for the other core config functions in there so that you'd be interacting with config from the one place.
Pros:
- Config related calls are brought together into one place.
- Don't have to remember to declare "global $CFG;" (or remove it after you stop using CFG in a function), and helps avoid silent config failures when 3rd party code (or any code for that matter) forgot to global $CFG
- Encourages developers to use less globals
- Moves configuration management into a nicely namespaced class rather than a collection of global functions
Cons:
- As pointed out (quite rightly) by Eloy, its already covered by the core get_config function. Calling "get_config('core', 'somesetting')" achieves almost the exact same result (when a setting simply doesn't exist, get_config returns false, where an unset $CFG value results in null (and a php notice).
- For the same reason as above, you get some of the pro's above just by using get_config.