1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bencagri\Artisan\Deployer; |
4
|
|
|
|
5
|
|
|
use Bencagri\Artisan\Deployer\Server\Property; |
6
|
|
|
use Bencagri\Artisan\Deployer\Server\Server; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class Context |
12
|
|
|
{ |
13
|
|
|
private $localHost; |
14
|
|
|
private $dryRun; |
15
|
|
|
private $debug; |
16
|
|
|
private $input; |
17
|
|
|
private $output; |
18
|
|
|
private $projectDir; |
19
|
|
|
private $logFilePath; |
20
|
|
|
|
21
|
|
|
public function __construct(InputInterface $input, OutputInterface $output, string $projectDir, string $logFilePath, bool $isDryRun, bool $isVerbose) |
22
|
|
|
{ |
23
|
|
|
$this->input = $input; |
24
|
|
|
$this->output = $output; |
25
|
|
|
$this->projectDir = $projectDir; |
26
|
|
|
$this->logFilePath = $logFilePath; |
27
|
|
|
$this->dryRun = $isDryRun; |
28
|
|
|
$this->debug = $isVerbose; |
29
|
|
|
|
30
|
|
|
$this->localHost = $this->createLocalHost(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function __toString() : string |
34
|
|
|
{ |
35
|
|
|
return sprintf( |
36
|
|
|
'dry-run = %s, debug = %s, logFile = %s, localHost = Object(Server), input = Object(InputInterface), output = Object(OutputInterface)', |
37
|
|
|
$this->dryRun ? 'true' : 'false', |
38
|
|
|
$this->debug ? 'true' : 'false', |
39
|
|
|
$this->logFilePath |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getLocalHost() : Server |
44
|
|
|
{ |
45
|
|
|
return $this->localHost; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getLogFilePath() : string |
49
|
|
|
{ |
50
|
|
|
return $this->logFilePath; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getLocalProjectRootDir() : string |
54
|
|
|
{ |
55
|
|
|
return $this->localHost->get(Property::project_dir); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function isDryRun() : bool |
59
|
|
|
{ |
60
|
|
|
return $this->dryRun; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function isDebug() : bool |
64
|
|
|
{ |
65
|
|
|
return $this->debug; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getInput() : InputInterface |
69
|
|
|
{ |
70
|
|
|
return $this->input; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getOutput() : OutputInterface |
74
|
|
|
{ |
75
|
|
|
return $this->output; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function createLocalHost() : Server |
79
|
|
|
{ |
80
|
|
|
$localhost = new Server('localhost'); |
81
|
|
|
$localhost->set(Property::project_dir, $this->projectDir); |
82
|
|
|
|
83
|
|
|
return $localhost; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|