-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-validator.php
More file actions
executable file
·97 lines (78 loc) · 2.7 KB
/
Copy pathconfig-validator.php
File metadata and controls
executable file
·97 lines (78 loc) · 2.7 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env php
<?php
/**
* Configuration Validator
*
* Validates universe.toml configuration files.
* Usage: php tools/config-validator.php [path/to/universe.toml]
*/
class ConfigValidator {
private array $errors = [];
private array $warnings = [];
public function validate(string $configPath): bool {
if (!file_exists($configPath)) {
$this->errors[] = "Configuration file not found: {$configPath}";
return false;
}
$content = file_get_contents($configPath);
$this->validateSyntax($content);
$this->validateStructure($content);
$this->validateTargets($content);
return empty($this->errors);
}
private function validateSyntax(string $content): void {
// Basic TOML syntax checks
if (!str_contains($content, '[project]')) {
$this->errors[] = "Missing [project] section";
}
}
private function validateStructure(string $content): void {
$requiredFields = ['name', 'version', 'entry'];
foreach ($requiredFields as $field) {
if (!preg_match("/^\s*{$field}\s*=/m", $content)) {
$this->errors[] = "Missing required field: {$field}";
}
}
}
private function validateTargets(string $content): void {
$targets = ['native', 'wasm', 'ios', 'embedded'];
foreach ($targets as $target) {
if (preg_match("/\[targets\.{$target}\]/", $content)) {
if (!preg_match("/^\s*enabled\s*=\s*(true|false)/m", $content)) {
$this->warnings[] = "Target '{$target}' is missing 'enabled' field";
}
}
}
}
public function getErrors(): array {
return $this->errors;
}
public function getWarnings(): array {
return $this->warnings;
}
public function printReport(): void {
if (empty($this->errors) && empty($this->warnings)) {
echo "✅ Configuration is valid!\n";
return;
}
if (!empty($this->errors)) {
echo "❌ Errors:\n";
foreach ($this->errors as $error) {
echo " - {$error}\n";
}
}
if (!empty($this->warnings)) {
echo "⚠️ Warnings:\n";
foreach ($this->warnings as $warning) {
echo " - {$warning}\n";
}
}
}
}
if (php_sapi_name() === 'cli') {
$configPath = $argv[1] ?? 'universe.toml';
$validator = new ConfigValidator();
$isValid = $validator->validate($configPath);
$validator->printReport();
exit($isValid ? 0 : 1);
}