$constants * @phpstan-param-out array $constants */ function collectProperties(string $prefix, array $properties, array &$constants) : void{ foreach($properties as $propertyName => $property){ $fullPropertyName = ($prefix !== "" ? $prefix . "." : "") . $propertyName; $constName = str_replace([".", "-"], "_", strtoupper($fullPropertyName)); $constants[$constName] = $fullPropertyName; if(is_array($property)){ collectProperties($fullPropertyName, $property, $constants); } } } collectProperties("", $defaultConfig, $constants); ksort($constants, SORT_STRING); $file = fopen(dirname(__DIR__) . '/src/YmlServerProperties.php', 'wb'); if($file === false){ fwrite(STDERR, "Failed to open output file\n"); exit(1); } fwrite($file, " $propertyName){ fwrite($file, "\tpublic const $constName = '$propertyName';\n"); } fwrite($file, "}\n"); fclose($file); echo "Done. Don't forget to run CS fixup after generating code.\n";