[CONFIG] Make it possible to write module configuration in a config.{php,yml,yaml,xml} file and set each value as properties in the module object

This commit is contained in:
2021-08-21 22:30:24 +01:00
parent 3587b8dc1d
commit c71a4b06ef
6 changed files with 83 additions and 19 deletions

View File

@@ -27,18 +27,25 @@ use App\Util\Common;
abstract class Module
{
/**
* TODO Handle configuration
*
* @codeCoverageIgnore
* Load values from the config and set them as properties on each module object
*/
public function __construct()
public function loadConfig()
{
// Load Module settings
foreach (Common::config(static::class) as $aname => $avalue) {
$this->{$aname} = $avalue;
foreach (Common::config(static::MODULE_TYPE . 's') as $module => $values) {
if ($module == $this->name()) {
foreach ($values as $property => $value) {
$this->{$property} = $value;
}
}
}
}
public static function name()
{
return mb_strtolower(explode('\\', static::class)[2]);
}
/**
* Serialize the class to store in the cache
*