# HG changeset patch # User luka # Date 1697677472 14400 # Node ID 4216c0dc638c39e34e8d3972f51c2c2e70979cf4 # Parent 769a17898cc0c5fcaf22087331b660e684cdd2ff Added base php cs fixer added config helper to maintain config diff -r 769a17898cc0 -r 4216c0dc638c .php-cs-fixer.dist.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.php-cs-fixer.dist.php Wed Oct 18 21:04:32 2023 -0400 @@ -0,0 +1,14 @@ +in(__DIR__) + ->exclude('.hg') +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@Symfony' => true, + 'full_opening_tag' => false, + ]) + ->setFinder($finder) +; diff -r 769a17898cc0 -r 4216c0dc638c src/ConfigHelper.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ConfigHelper.php Wed Oct 18 21:04:32 2023 -0400 @@ -0,0 +1,115 @@ +\n[`, it will get converted to `=> [` + * + * @see https://www.php.net/manual/en/function.var-export.php + */ + public static function varexport($expression, $return = false) + { + $export = var_export($expression, true); + $patterns = [ + "/array \(/" => '[', + "/^([ ]*)\)(,?)$/m" => '$1]$2', + "/=>[ ]?\n[ ]+\[/" => '=> [', + "/([ ]*)(\'[^\']+\') => ([\[\'])/" => '$1$2 => $3', + ]; + $export = preg_replace(array_keys($patterns), array_values($patterns), $export); + if ((bool) $return) { + return $export; + } else { + echo $export; + } + } + + protected static function format_file(string $path) + { + exec('php-cs-fixer fix '.$path); + } + + public static function set_up_tables() + { + $schema = \DB::connection()->getDoctrineSchemaManager(); + // get all the tables available in the db + $tables = collect($schema->listTableNames())->all(); + + $insert_tables = []; + foreach ($tables as $table) { + $columns = []; + $table_columns = $schema->introspectTable($table)->getColumns(); + + foreach ($table_columns as $column) { + $columns[$column->getName()] = [ + 'should_insert' => [ + 'controller' => true, + 'model' => true, + 'requests' => true, + 'views' => true, + ], + ]; + } + + $insert_tables[$table] = $columns; + + } + self::merge_array_priority(self::$config['tables'], $insert_tables); + + return $tables; + } + + private static function merge_array_priority(&$priority, $merged) + { + foreach ($merged as $key => $value) { + // if the priority key is not set, automatically add the merged values + if (!isset($priority[$key])) { + $priority[$key] = $value; + } else { + // if the value is an array recursively merge + if (is_array($value) && is_array($priority[$key])) { + self::merge_array_priority($priority[$key], $value); + } + } + } + } +}