1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mcustiel\Phiremock\Server\Utils\Config; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\CertificateKeyPath; |
7
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\CertificatePath; |
8
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\ExpectationsDirectory; |
9
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\HostInterface; |
10
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\Passphrase; |
11
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\PhpFactoryFqcn; |
12
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\Port; |
13
|
|
|
use Mcustiel\Phiremock\Server\Cli\Options\SecureOptions; |
14
|
|
|
|
15
|
|
|
class Config |
16
|
|
|
{ |
17
|
|
|
/** @var array */ |
18
|
|
|
private $configurationArray; |
19
|
|
|
|
20
|
|
|
public function __construct(array $configurationArray) |
21
|
|
|
{ |
22
|
|
|
$this->configurationArray = $configurationArray; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getInterfaceIp(): HostInterface |
26
|
|
|
{ |
27
|
|
|
return new HostInterface($this->configurationArray['ip']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getPort(): Port |
31
|
|
|
{ |
32
|
|
|
return new Port((int) $this->configurationArray['port']); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function isDebugMode(): bool |
36
|
|
|
{ |
37
|
|
|
return $this->configurationArray['debug']; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getExpectationsPath(): ExpectationsDirectory |
41
|
|
|
{ |
42
|
|
|
return new ExpectationsDirectory($this->configurationArray['expectations-dir']); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getFactoryClassName(): PhpFactoryFqcn |
46
|
|
|
{ |
47
|
|
|
return new PhpFactoryFqcn($this->configurationArray['factory-class']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isSecure(): bool |
51
|
|
|
{ |
52
|
|
|
return isset($this->configurationArray['certificate']) |
53
|
|
|
&& isset($this->configurationArray['certificate-key']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @throws Exception */ |
57
|
|
|
public function getSecureOptions(): ?SecureOptions |
58
|
|
|
{ |
59
|
|
|
if (!$this->isSecure()) { |
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return new SecureOptions( |
64
|
|
|
new CertificatePath($this->configurationArray['certificate']), |
65
|
|
|
new CertificateKeyPath($this->configurationArray['certificate-key']), |
66
|
|
|
isset($this->configurationArray['cert-passphrase']) |
67
|
|
|
? new Passphrase($this->configurationArray['cert-passphrase']) |
68
|
|
|
: null |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|