tsugi
tsugi copied to clipboard
Convert $CFG options to be YAML or JSON driven
It seems like configuration settings are more or less thrown in as people think of them into config-dist.php. Would it possibly be easier to read as well as modify and put into version control if this was abstracted to a yaml or json file that config then loads in? This would also make it easier to write a CLI / YO that could write the config options automatically for people increasing devUX down stream
Definitely a thought - because of the PHP runtime, pre-compiling, and APC cache, putting config in PHP is effectively 100% free. A JSON or YAML would be an extra file open on every request / response cycle. Core code needs to be cheap and fast.
Now a possible solution would be to write a class or change the ConfigInfo class to point to a YAML or JSON file - then the config.php file would just use ConfigInfo to load the file and set all the variables. Best of both worlds - scorching fast and easy flexibility.
Also the "config-dist.php" -> "config.php" convention came from Moodle :) They have auto configuration that writes the file. Tsugi could support auto-config whether it was PHP, YAML, or JSON.
D8/Backdrop write to yaml / parse back in then cache the reference.
You could also cheat and name the file config.yaml.php and opcache would store it ;)
I think the config looks okay but could be more readable/organized. The CFG doesn't actually start until a few pages in where in the Moodle Version it's right at the top and easier to tell what you have to set.
Wordpress looks like it uses define in a php file. That seems readable too and not many settings at all.
The performance of ini files and parse_ini_file also seems to be pretty high, and the last comment there about reading the file, caching it and loading it seems interesting. I also noticed this php library and looks like they might have built in cache, no idea of the performance. https://github.com/hassankhan/config
Might be worth using something like that if this was changed
I don't know how much benefit one format would have over another though, but realistically the performance cost of reading in a file seems negligible compared to any database access if the page does that.
I don't like YAML or ini files. PHP is the quickest and most high performance way to do this - it is compiled dynamically.
The layout of config-dist.php (i.e. not all the good stuff is at the top) is just because of a lot of evolution and no refactoring to clean things up. One thing that made things a lot more complex was things like Lessons, apphome, memcache, and Koseu. This becomes a combination of the Tsugi configuration and the Koseu configuration so it get s a little unweildly. There is also the
ConfigInfo class that is supposed to document everything that tends to fall behind config-dist.php
If I was going to do anything, it would be to separate the config.php into Tsugi and Koseu settings and put the Koseu settings in the parent directory