-
Notifications
You must be signed in to change notification settings - Fork 3
/
Updater.php
66 lines (49 loc) · 1.53 KB
/
Updater.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
<?php
Class Updater {
public Array $files;
public String $folder;
public String $remoteBase;
function __construct($folder, $remoteBase){
$this->folder = $folder;
$this->remoteBase = $remoteBase;
$this->files = [];
$this->setAllPhpFiles();
}
function setAllPhpFiles(): void {
$dirFiles = scandir(empty($this->folder) ? "." : $this->folder);
foreach ($dirFiles as $file) {
if(array_reverse(explode(".", $file))[0] == 'php'){
array_push($this->files, $file);
}
}
}
function needUpdate($file): Bool {
$remote = $this->getRemote($file);
$local = $this->getLocal($file);
if($remote != $local){
return true;
}
return false;
}
function update($file): Bool {
$rContent = $this->getRemote($file);
return file_put_contents($this->folder.$file, $rContent);
}
function getRemote($file): String {
return file_get_contents($this->remoteBase.$this->folder.$file);
}
function getLocal($file): String {
return file_get_contents($this->folder.$file);
}
}
$updater = new Updater("src/", "https://raw.githubusercontent.com/andersonmendess/GWatcher/master/");
foreach ($updater->files as $file) {
if($updater->needUpdate($file)){
echo "(+) Found newer version of $file \n";
if($updater->update($file)){
echo " - Updating $file \n";
}
} else {
echo "$file is Updated \n";
}
}