1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Executor; |
9
|
|
|
|
10
|
|
|
use Deployer\Exception\Exception; |
11
|
|
|
use Deployer\Exception\RunException; |
12
|
|
|
use Deployer\Host\Host; |
13
|
|
|
use Deployer\Task\Task; |
14
|
|
|
use Symfony\Component\Console\Helper\Table; |
15
|
|
|
use Symfony\Component\Console\Helper\TableStyle; |
16
|
|
|
use Symfony\Component\Console\Input\Input; |
17
|
|
|
use Symfony\Component\Console\Output\Output; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Throwable; |
20
|
|
|
|
21
|
|
|
class Planner |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Table |
25
|
|
|
*/ |
26
|
|
|
private $table; |
27
|
|
|
|
28
|
|
|
private $template; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Planner constructor. |
32
|
|
|
* |
33
|
|
|
* @param OutputInterface $output |
34
|
|
|
* @param Host[] $hosts |
35
|
|
|
*/ |
36
|
|
|
public function __construct(OutputInterface $output, $hosts) |
37
|
|
|
{ |
38
|
|
|
$headers = []; |
39
|
|
|
$this->template = []; |
40
|
|
|
foreach ($hosts as $host) { |
41
|
|
|
$headers[] = $host->tag(); |
42
|
|
|
$this->template[] = $host->alias(); |
43
|
|
|
} |
44
|
|
|
$this->table = new Table($output); |
45
|
|
|
$this->table->setHeaders($headers); |
46
|
|
|
$this->table->setStyle('box'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Host[] $hosts |
51
|
|
|
* @param Task $task |
52
|
|
|
*/ |
53
|
|
|
public function commit(array $hosts, Task $task) |
54
|
|
|
{ |
55
|
|
|
if (count($hosts) === 1 && $hosts[0]->alias() === 'localhost') { |
56
|
|
|
$row = []; |
57
|
|
|
foreach ($this->template as $alias) { |
58
|
|
|
$row[] = "-"; |
59
|
|
|
} |
60
|
|
|
$row[] = $task->getName() . " (local)"; |
61
|
|
|
$this->table->addRow($row); |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
$row = []; |
65
|
|
|
foreach ($this->template as $alias) { |
66
|
|
|
$on = "-"; |
67
|
|
|
foreach ($hosts as $host) { |
68
|
|
|
if ($alias === $host->alias()) { |
69
|
|
|
$on = $task->getName(); |
70
|
|
|
break; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
$row[] = $on; |
74
|
|
|
} |
75
|
|
|
$this->table->addRow($row); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function render() |
79
|
|
|
{ |
80
|
|
|
$this->table->render(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|