-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebDeploy.php
88 lines (55 loc) · 1.86 KB
/
WebDeploy.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
<?php
/**
* WebDeploy
* https://github.com/acuna-public/WebDeploy
* @author Acuna
* @license GPLv3
* @version 1.4
*/
require_once 'AssocArray.php';
require_once 'WebDeploy.php';
require_once 'ConfigRule.php';
require_once 'Deployment.php';
abstract class WebDeploy extends \AssocArray {
const VERSION = '1.4';
protected $matched = [], $filters = [];
public $debug = 0, $git;
public $token, $configs, $config = [];
public \Storage $storage;
public \Logger $logger;
function __construct (string $token, array $configs, \Storage $storage, \Logger $logger) {
parent::__construct ();
$this->token = $token;
$this->configs = $configs;
$this->storage = $storage;
$this->logger = $logger;
$this->logger->setName ('WebDeploy', self::VERSION);
}
function getRequiredPairs (): array {
return ['repository', 'files'];
}
protected function addRules () {
$rule = new \WebDeploy\ConfigRule ($this);
if ($rule->compare ()) {
$deploy = new \WebDeploy\Deployment ($this, $rule);
$deploy->process ();
$this->logger->setLogLevel ();
}
}
protected function setRepositoryName ($name) {
$this->set ('repository', $name);
}
abstract protected function onParse ();
abstract protected function isDeploy (): bool;
final function deploy () {
if ($this->isDeploy ()) {
if (isset ($this->configs[$this->get ('repository')])) {
if ($this->config = $this->configs[$this->get ('repository')]) {
$this->onParse ();
$this->addRules ();
} else $this->logger->error ('Config is empty', 406);
} else $this->logger->error ('Repository \''.$this->get ('repository').'\' not found in deployment config', 404);
}
echo json_encode ($this->logger->message, JSON_PRETTY_PRINT);
}
}