-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathContext.php
More file actions
84 lines (69 loc) · 2.19 KB
/
Copy pathContext.php
File metadata and controls
84 lines (69 loc) · 2.19 KB
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
<?php
/*
* This file is part of the EasyDeploy project.
*
* (c) Javier Eguiluz <javier.eguiluz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EasyCorp\Bundle\EasyDeployBundle;
use EasyCorp\Bundle\EasyDeployBundle\Server\Property;
use EasyCorp\Bundle\EasyDeployBundle\Server\Server;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* It implements the "Context Object" pattern to encapsulate the global state of
* the deployment in an immutable object.
*/
class Context implements \Stringable
{
private readonly Server $localHost;
public function __construct(private readonly InputInterface $input, private readonly OutputInterface $output, private readonly string $projectDir, private readonly string $logFilePath, private readonly bool $dryRun, private readonly bool $debug)
{
$this->localHost = $this->createLocalHost();
}
public function __toString(): string
{
return sprintf(
'dry-run = %s, debug = %s, logFile = %s, localHost = Object(Server), input = Object(InputInterface), output = Object(OutputInterface)',
$this->dryRun ? 'true' : 'false',
$this->debug ? 'true' : 'false',
$this->logFilePath
);
}
public function getLocalHost(): Server
{
return $this->localHost;
}
public function getLogFilePath(): string
{
return $this->logFilePath;
}
public function getLocalProjectRootDir(): string
{
return $this->localHost->get(Property::project_dir);
}
public function isDryRun(): bool
{
return $this->dryRun;
}
public function isDebug(): bool
{
return $this->debug;
}
public function getInput(): InputInterface
{
return $this->input;
}
public function getOutput(): OutputInterface
{
return $this->output;
}
private function createLocalHost(): Server
{
$localhost = new Server('localhost');
$localhost->set(Property::project_dir, $this->projectDir);
return $localhost;
}
}