|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Wolnościowiec / WebDeploy |
|
5
|
|
|
* ------------------------ |
|
6
|
|
|
* |
|
7
|
|
|
* Framework for creation of post-install scripts dedicated |
|
8
|
|
|
* for applications hosted on shared hosting (without access to the shell). |
|
9
|
|
|
* |
|
10
|
|
|
* A part of an anarchist portal - wolnosciowiec.net |
|
11
|
|
|
* |
|
12
|
|
|
* Wolnościowiec is a project to integrate the movement |
|
13
|
|
|
* of people who strive to build a society based on |
|
14
|
|
|
* solidarity, freedom, equality with a respect for |
|
15
|
|
|
* individual and cooperation of each other. |
|
16
|
|
|
* |
|
17
|
|
|
* We support human rights, animal rights, feminism, |
|
18
|
|
|
* anti-capitalism (taking over the production by workers), |
|
19
|
|
|
* anti-racism, and internationalism. We negate |
|
20
|
|
|
* the political fight and politicians at all. |
|
21
|
|
|
* |
|
22
|
|
|
* http://wolnosciowiec.net/en |
|
23
|
|
|
* |
|
24
|
|
|
* License: LGPLv3 |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Wolnosciowiec\WebDeploy; |
|
28
|
|
|
|
|
29
|
|
|
use GuzzleHttp\Psr7\Response; |
|
30
|
|
|
use Psr\Http\Message\RequestInterface; |
|
31
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
32
|
|
|
use Wolnosciowiec\WebDeploy\Exceptions\DeploymentFailureException; |
|
33
|
|
|
use Wolnosciowiec\WebDeploy\Tasks\TaskInterface; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @package Wolnosciowiec\WebDeploy |
|
37
|
|
|
*/ |
|
38
|
|
|
class Kernel |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @var TaskInterface[] $tasks |
|
42
|
|
|
*/ |
|
43
|
|
|
private $tasks; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param TaskInterface $task |
|
47
|
|
|
* @return Kernel |
|
48
|
|
|
*/ |
|
49
|
|
|
public function addTask(TaskInterface $task): Kernel |
|
50
|
|
|
{ |
|
51
|
|
|
$this->tasks[] = $task; |
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return TaskInterface[] |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getTasks() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->tasks; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param RequestInterface $request |
|
65
|
|
|
* @return ResponseInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
public function handleRequest(RequestInterface $request) |
|
68
|
|
|
{ |
|
69
|
|
|
$output = []; |
|
70
|
|
|
$num = 0; |
|
71
|
|
|
|
|
72
|
|
|
foreach ($this->tasks as $task) { |
|
73
|
|
|
$taskName = ++$num . '_' . get_class($task); |
|
74
|
|
|
|
|
75
|
|
|
try { |
|
76
|
|
|
$output[$taskName] = $task->execute($request); |
|
77
|
|
|
|
|
78
|
|
|
} catch (DeploymentFailureException $e) { |
|
79
|
|
|
return new Response( |
|
80
|
|
|
500, [ |
|
81
|
|
|
'Content-Type: application/json' |
|
82
|
|
|
], |
|
83
|
|
|
json_encode([ |
|
84
|
|
|
'success' => false, |
|
85
|
|
|
'message' => 'Deployment failed', |
|
86
|
|
|
'task_failed' => $taskName, |
|
87
|
|
|
'details' => $e->getMessage(), |
|
88
|
|
|
], JSON_PRETTY_PRINT) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return new Response( |
|
94
|
|
|
200, [ |
|
95
|
|
|
'Content-Type: application/json' |
|
96
|
|
|
], |
|
97
|
|
|
json_encode([ |
|
98
|
|
|
'success' => true, |
|
99
|
|
|
'results' => $output, |
|
100
|
|
|
], JSON_PRETTY_PRINT) |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
} |