-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_api_map.php
More file actions
57 lines (43 loc) · 1.68 KB
/
generate_api_map.php
File metadata and controls
57 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
$startPath = __DIR__ . '/src/Generated';
$outputFile = __DIR__ . '/src/Laravel/amazon_api_map.php';
if (! is_dir($startPath)) {
exit("❌ Fehler: Verzeichnis $startPath nicht gefunden.\n");
}
$apiMap = [];
$baseNamespace = 'KBart\\AmazonAds\\Generated';
// Ebene 1: Die Namespaces (Billing, Common, etc.)
$namespaces = array_filter(glob($startPath . DIRECTORY_SEPARATOR . '*'), 'is_dir');
foreach ($namespaces as $nsPath) {
$namespaceName = basename($nsPath);
$apiFolderPath = $nsPath . DIRECTORY_SEPARATOR . 'Api';
if (is_dir($apiFolderPath)) {
$files = scandir($apiFolderPath);
foreach ($files as $file) {
if (str_ends_with($file, 'Api.php')) {
// Key generieren: "BillingDocumentsApi.php" -> "BillingDocuments"
$key = str_replace('Api.php', '', $file);
// Classname generieren
$className = str_replace('.php', '', $file);
// Value generieren (FQCN)
$fqcn = "\\{$baseNamespace}\\{$namespaceName}\\Api\\{$className}";
$apiMap[$namespaceName][$key] = $fqcn;
}
}
}
}
// Array in PHP-Code umwandeln
$content = "<?php\n\n// Automatisch generiert am " . date('d.m.Y H:i:s') . "\n\nreturn [\n";
foreach ($apiMap as $ns => $apis) {
$content .= " '$ns' => [\n";
foreach ($apis as $key => $fqcn) {
$content .= " '$key' => {$fqcn}::class,\n";
}
$content .= " ],\n";
}
$content .= "];\n";
if (file_put_contents($outputFile, $content)) {
echo "🗺️ API Map erfolgreich generiert: src/Laravel/amazon_api_map.php\n";
} else {
echo "❌ Fehler beim Schreiben der Datei '$outputFile'.\n";
}