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('unlinkUnlessDefault')) { |
43
|
|
|
function unlinkUnlessDefault(string $filepath): void |
44
|
|
|
{ |
45
|
|
|
$protected = [ |
46
|
|
|
'app.css', |
47
|
|
|
'index.blade.php', |
48
|
|
|
'404.blade.php', |
49
|
|
|
'.gitkeep', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
if (! in_array(basename($filepath), $protected)) { |
53
|
|
|
unlink($filepath); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (! function_exists('strip_newlines')) { |
59
|
|
|
function strip_newlines(string $string, bool $keepUnixEndings = false): string |
60
|
|
|
{ |
61
|
|
|
if ($keepUnixEndings) { |
62
|
|
|
return str_replace("\r", '', $string); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return str_replace(["\r", "\n"], '', $string); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (! function_exists('strip_indentation')) { |
70
|
|
|
function strip_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string |
71
|
|
|
{ |
72
|
|
|
$indentation = $indentUsingSpaces ? str_repeat(' ', $indentationLength) : "\t"; |
73
|
|
|
|
74
|
|
|
return str_replace($indentation, '', $string); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (! function_exists('strip_newlines_and_indentation')) { |
79
|
|
|
function strip_newlines_and_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string |
80
|
|
|
{ |
81
|
|
|
return strip_newlines(strip_indentation($string, $indentUsingSpaces, $indentationLength)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|