|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\File; |
|
4
|
|
|
|
|
5
|
|
|
if (! function_exists('unlinkIfExists')) { |
|
6
|
|
|
function unlinkIfExists(string $filepath): void |
|
7
|
|
|
{ |
|
8
|
|
|
if (file_exists($filepath)) { |
|
9
|
|
|
unlink($filepath); |
|
10
|
|
|
} |
|
11
|
|
|
} |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
if (! function_exists('backupDirectory')) { |
|
15
|
|
|
function backupDirectory(string $directory): void |
|
16
|
|
|
{ |
|
17
|
|
|
if (file_exists($directory)) { |
|
18
|
|
|
File::copyDirectory($directory, $directory.'-bak', true); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (! function_exists('restoreDirectory')) { |
|
24
|
|
|
function restoreDirectory(string $directory): void |
|
25
|
|
|
{ |
|
26
|
|
|
if (file_exists($directory.'-bak')) { |
|
27
|
|
|
File::moveDirectory($directory.'-bak', $directory, true); |
|
28
|
|
|
File::deleteDirectory($directory.'-bak'); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (! function_exists('deleteDirectory')) { |
|
34
|
|
|
function deleteDirectory(string $directory): void |
|
35
|
|
|
{ |
|
36
|
|
|
if (file_exists($directory)) { |
|
37
|
|
|
File::deleteDirectory($directory); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (! function_exists('makeDirectory')) { |
|
43
|
|
|
function makeDirectory(string $directory): void |
|
44
|
|
|
{ |
|
45
|
|
|
if (file_exists($directory)) { |
|
46
|
|
|
File::makeDirectory($directory); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (! function_exists('unlinkUnlessDefault')) { |
|
52
|
|
|
function unlinkUnlessDefault(string $filepath): void |
|
53
|
|
|
{ |
|
54
|
|
|
$protected = [ |
|
55
|
|
|
'app.css', |
|
56
|
|
|
'index.blade.php', |
|
57
|
|
|
'404.blade.php', |
|
58
|
|
|
'.gitkeep', |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
if (! in_array(basename($filepath), $protected)) { |
|
62
|
|
|
unlink($filepath); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (! function_exists('strip_newlines')) { |
|
68
|
|
|
function strip_newlines(string $string, bool $keepUnixEndings = false): string |
|
69
|
|
|
{ |
|
70
|
|
|
if ($keepUnixEndings) { |
|
71
|
|
|
return str_replace("\r", '', $string); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return str_replace(["\r", "\n"], '', $string); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (! function_exists('strip_indentation')) { |
|
79
|
|
|
function strip_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string |
|
80
|
|
|
{ |
|
81
|
|
|
$indentation = $indentUsingSpaces ? str_repeat(' ', $indentationLength) : "\t"; |
|
82
|
|
|
|
|
83
|
|
|
return str_replace($indentation, '', $string); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (! function_exists('strip_newlines_and_indentation')) { |
|
88
|
|
|
function strip_newlines_and_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string |
|
89
|
|
|
{ |
|
90
|
|
|
return strip_newlines(strip_indentation($string, $indentUsingSpaces, $indentationLength)); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|