forked from easy-swoole/doc-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.php
189 lines (188 loc) · 5.75 KB
/
installer.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* Created by PhpStorm.
* User: yf
* Date: 2017/9/6
* Time: 上午11:24
*/
class FileUtil {
static function createDir($dirPath){
if(!is_dir($dirPath)){
try{
return mkdir($dirPath,0755,true);
}catch (\Exception $exception){
return false;
}
}else{
return true;
}
}
static function deleteDir($dirPath){
if(self::clearDir($dirPath)){
try{
return rmdir($dirPath);
}catch (\Exception $exception){
return false;
}
}else{
return false;
}
}
static function clearDir($dirPath){
if (!is_dir($dirPath)) {
return false;
}
try{
$dirHandle = opendir($dirPath);
if(!$dirHandle){
return false;
}
while (false !== ($file = readdir($dirHandle))) {
if ($file == '.' || $file == '..') {
continue;
}
if (!is_dir($dirPath ."/". $file)) {
if(!self::deleteFile($dirPath ."/". $file)){
closedir($dirHandle);
return false;
}
} else {
if(!self::deleteDir($dirPath ."/". $file)){
closedir($dirHandle);
return false;
}
}
}
closedir($dirHandle);
return true;
}catch (\Exception $exception){
return false;
}
}
static function copyDir($dirPath,$targetPath,$overwrite = true){
if (!is_dir($dirPath)) {
return false;
}
if (!file_exists($targetPath)) {
if(!self:: createDir($targetPath)){
return false;
}
}
try{
$dirHandle = opendir($dirPath);
if(!$dirHandle){
return false;
}
while (false !== ($file = readdir($dirHandle))) {
if ($file == '.' || $file == '..') {
continue;
}
if (!is_dir($dirPath ."/". $file)) {
if(!self::copyFile($dirPath ."/". $file, $targetPath ."/". $file, $overwrite)){
closedir($dirHandle);
return false;
}
} else {
if(!self::copyDir($dirPath ."/". $file, $targetPath ."/". $file, $overwrite)){
closedir($dirHandle);
return false;
};
}
}
closedir($dirHandle);
return true;
}catch (\Exception $exception){
return false;
}
}
static function moveDir($dirPath,$targetPath,$overwrite = true){
try{
if(self::copyDir($dirPath,$targetPath,$overwrite)){
return self::deleteDir($dirPath);
}else{
return false;
}
}catch (\Exception $exception){
return false;
}
}
static function createFile($filePath, $overwrite = true){
if (file_exists($filePath) && $overwrite == false) {
return false;
} elseif (file_exists($filePath) && $overwrite == true) {
if(!self::deleteFile($filePath)){
return false;
}
}
$aimDir = dirname($filePath);
if(self::createDir($aimDir)){
try{
return touch($filePath);
}catch (\Exception $exception){
return false;
}
}else{
return false;
}
}
static function saveFile($filePath,$content, $overwrite = true){
if(self::createFile($filePath,$overwrite)){
return file_put_contents($filePath,$content);
}else{
return false;
}
}
static function copyFile($filePath,$targetFilePath,$overwrite = true){
if (!file_exists($filePath)) {
return false;
}
if (file_exists($targetFilePath) && $overwrite == false) {
return false;
} elseif (file_exists($targetFilePath) && $overwrite == true) {
if(!self::deleteFile($targetFilePath)){
return false;
}
}
$aimDir = dirname($filePath);
if(!self::createDir($aimDir)){
return false;
};
return copy($filePath, $targetFilePath);
}
static function moveFile($filePath,$targetFilePath,$overwrite = true){
if (!file_exists($filePath)) {
return false;
}
if (file_exists($targetFilePath) && $overwrite == false) {
return false;
} elseif (file_exists($targetFilePath) && $overwrite == true) {
if(!self::deleteFile($targetFilePath)){
return false;
}
}
$targetDir = dirname($targetFilePath);
if(!self:: createDir($targetDir)){
return false;
}
return rename($filePath, $targetFilePath);
}
static function deleteFile($filePath){
try{
unlink($filePath);
return true;
}catch (\Exception $exception){
return false;
}
}
}
$zip = new ZipArchive();
echo "start download easyswoole...\n";
copy('https://codeload.github.com/easy-swoole/easyswoole/zip/master','./easyswoole-master.zip');
echo "unzip...\n";
$zip->open("easyswoole-master.zip");
echo "extract....\n";
$zip->extractTo("./");
FileUtil::moveDir("./easyswoole-master/src",'./');
FileUtil::deleteDir("./easyswoole-master");
FileUtil::deleteFile('./easyswoole-master.zip');
echo "install success";