# HG changeset patch # User luka # Date 1701530432 18000 # Node ID a9ff874afdbdeae33110bdd82eb0937be96ec7ee # Parent d4730c14806d382d627501cc43a65a3a8a38fced better comments for config helper diff -r d4730c14806d -r a9ff874afdbd src/ConfigHelper.php --- a/src/ConfigHelper.php Sat Dec 02 10:18:52 2023 -0500 +++ b/src/ConfigHelper.php Sat Dec 02 10:20:32 2023 -0500 @@ -4,47 +4,76 @@ class ConfigHelper { + // Config array public static $config = []; + + // Config file name constant public const CONFIG_FILE_NAME = 'mf_config.php'; + + // Config path variable public static $config_path; + /** + * Set up configuration path + * + * @param string $base_path + */ public static function setup_config_path(string $base_path) { self::$config_path = $base_path.'/'.self::CONFIG_FILE_NAME; } + /** + * Get configuration path + * + * @return string + */ protected static function get_config_path() { return self::$config_path; } + /** + * Write configuration into a file + */ public static function write_config() { $path = self::get_config_path(); $str = '\n[`, it will get converted to `=> [` * * @see https://www.php.net/manual/en/function.var-export.php + * + * @param mixed $expression + * @param boolean $return + * @return mixed */ public static function varexport($expression, $return = false) { @@ -63,15 +92,23 @@ } } + /** + * Format the given file + * + * @param string $path + */ protected static function format_file(string $path) { exec('php-cs-fixer fix '.$path); } + /** + * Set up tables + */ public static function set_up_tables() { $schema = \DB::connection()->getDoctrineSchemaManager(); - // get all the tables available in the db + // get all the tables available in the database $tables = collect($schema->listTableNames())->all(); $insert_tables = []; @@ -99,11 +136,18 @@ $insert_tables[$table]['columns'] = $columns; $insert_tables[$table]['type'] = 'default'; } + // Merge the new tables configuration into the initial config self::merge_array_priority(self::$config['tables'], $insert_tables); return $tables; } + /** + * Merge two arrays and ensure priority values do not get overwritten + * + * @param array $priority + * @param array $merged + */ private static function merge_array_priority(&$priority, $merged) { foreach ($merged as $key => $value) { @@ -111,7 +155,7 @@ if (!isset($priority[$key])) { $priority[$key] = $value; } else { - // if the value is an array recursively merge + // if the value is an array recursively merge with priority if (is_array($value) && is_array($priority[$key])) { self::merge_array_priority($priority[$key], $value); }