-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.php
More file actions
67 lines (55 loc) · 1.78 KB
/
Setup.php
File metadata and controls
67 lines (55 loc) · 1.78 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
<?php
final class Setup {
private static string $rootPath;
public static int $outSideVendor = 3;
public static function init() : void{
self::$rootPath = dirname(__DIR__, self::$outSideVendor)
. DIRECTORY_SEPARATOR;
}
public static function getRootPath(): string {
return self::$rootPath;
}
public static function createDirectories(array $directories) : void {
foreach ($directories as $dir) {
$path = self::$rootPath . $dir;
if (!is_dir($path)) {
if (mkdir($path, 0755, true)) {
echo "[*] Created directory: $path\n";
} else {
echo "[!] Failed to create directory: $path\n";
}
}
}
}
public static function createFiles(array $files) : void {
foreach ($files as $file => $content) {
$path = self::$rootPath . $file;
if (!file_exists($path)) {
if (file_put_contents($path, $content) !== false) {
echo "[*] Created file: $path\n";
} else {
echo "[!] Failed to create file: $path\n";
}
}
}
}
}
Setup::init();
$rootPath = Setup::getRootPath();
$directories = [
'template/caches',
'config',
'template/views'
];
$viewPath = '/template/views';
$cachePath = '/template/caches';
$files = [
'config/cool-view.php' => "<?php\n\nreturn [\n 'PrefixCharCoolEngine' => \"#\",\n 'ViewPath' => \"$viewPath\",\n 'CachePath' => \"$cachePath\",\n];",
];
Setup::createDirectories($directories);
Setup::createFiles($files);
$scriptPath = __FILE__;
if (file_exists($scriptPath)) {
unlink($scriptPath);
echo "[*] Setup is completed: $scriptPath\n";
}