1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Hyde\Framework\Hyde; |
4
|
|
|
use Illuminate\Support\Facades\File; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @deprecated You should not run tests in a production environment. |
8
|
|
|
*/ |
9
|
|
|
if (! function_exists('backup')) { |
10
|
|
|
function backup(string $filepath) |
11
|
|
|
{ |
12
|
|
|
if (file_exists($filepath)) { |
13
|
|
|
copy($filepath, $filepath.'.bak'); |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if (! function_exists('restore')) { |
19
|
|
|
function restore(string $filepath) |
20
|
|
|
{ |
21
|
|
|
if (file_exists($filepath.'.bak')) { |
22
|
|
|
copy($filepath.'.bak', $filepath); |
23
|
|
|
unlink($filepath.'.bak'); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (! function_exists('unlinkIfExists')) { |
29
|
|
|
function unlinkIfExists(string $filepath) |
30
|
|
|
{ |
31
|
|
|
if (file_exists($filepath)) { |
32
|
|
|
unlink($filepath); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if (! function_exists('backupDirectory')) { |
38
|
|
|
function backupDirectory(string $directory) |
39
|
|
|
{ |
40
|
|
|
if (file_exists($directory)) { |
41
|
|
|
File::copyDirectory($directory, $directory.'-bak', true); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (! function_exists('restoreDirectory')) { |
47
|
|
|
function restoreDirectory(string $directory) |
48
|
|
|
{ |
49
|
|
|
if (file_exists($directory.'-bak')) { |
50
|
|
|
File::moveDirectory($directory.'-bak', $directory, true); |
51
|
|
|
File::deleteDirectory($directory.'-bak'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (! function_exists('deleteDirectory')) { |
57
|
|
|
function deleteDirectory(string $directory) |
58
|
|
|
{ |
59
|
|
|
if (file_exists($directory)) { |
60
|
|
|
File::deleteDirectory($directory); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (! function_exists('createTestPost')) { |
66
|
|
|
/** @deprecated - You usually don't need an actual post file anymore. Use touch() instead. */ |
67
|
|
|
function createTestPost(?string $path = null): string |
68
|
|
|
{ |
69
|
|
|
$path = Hyde::path($path ?? '_posts/test-post.md'); |
70
|
|
|
file_put_contents($path, '--- |
71
|
|
|
title: My New Post |
72
|
|
|
category: blog |
73
|
|
|
author: Mr. Hyde |
74
|
|
|
--- |
75
|
|
|
|
76
|
|
|
# My New Post |
77
|
|
|
|
78
|
|
|
This is a post stub used in the automated tests |
79
|
|
|
'); |
80
|
|
|
|
81
|
|
|
return $path; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (! function_exists('unlinkUnlessDefault')) { |
86
|
|
|
function unlinkUnlessDefault(string $filepath) |
87
|
|
|
{ |
88
|
|
|
$protected = [ |
89
|
|
|
'app.css', |
90
|
|
|
'index.blade.php', |
91
|
|
|
'404.blade.php', |
92
|
|
|
'.gitkeep', |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
if (! in_array(basename($filepath), $protected)) { |
96
|
|
|
unlink($filepath); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|