|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Genkgo\Mail\Protocol; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* @codeCoverageIgnore |
|
8
|
|
|
*/ |
|
9
|
|
|
final class SecureConnectionOptions |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var float |
|
13
|
|
|
*/ |
|
14
|
|
|
private $timeout = 10; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var int |
|
18
|
|
|
*/ |
|
19
|
|
|
private $method; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array<string, mixed> |
|
23
|
|
|
*/ |
|
24
|
|
|
private $contextOptions = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param int $method |
|
28
|
|
|
* @param int $timeout |
|
29
|
|
|
* @param array<string, mixed> $contextOptions |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(int $method, int $timeout = 10, array $contextOptions = []) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->method = $method; |
|
34
|
|
|
$this->timeout = $timeout; |
|
|
|
|
|
|
35
|
|
|
$this->contextOptions = $contextOptions; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param float $connectionTimeout |
|
40
|
|
|
* @return SecureConnectionOptions |
|
41
|
|
|
*/ |
|
42
|
|
|
public function withTimeout(float $connectionTimeout): self |
|
43
|
|
|
{ |
|
44
|
|
|
$clone = clone $this; |
|
45
|
|
|
$clone->timeout = $connectionTimeout; |
|
46
|
|
|
return $clone; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param int $method |
|
51
|
|
|
* @return SecureConnectionOptions |
|
52
|
|
|
*/ |
|
53
|
|
|
public function withMethod(int $method): self |
|
54
|
|
|
{ |
|
55
|
|
|
$clone = clone $this; |
|
56
|
|
|
$clone->method = $method; |
|
57
|
|
|
return $clone; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param array<string, mixed> $contextOptions |
|
62
|
|
|
* @return SecureConnectionOptions |
|
63
|
|
|
*/ |
|
64
|
|
|
public function withContextOptions(array $contextOptions): self |
|
65
|
|
|
{ |
|
66
|
|
|
$clone = clone $this; |
|
67
|
|
|
$clone->contextOptions = $contextOptions; |
|
68
|
|
|
return $clone; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return float |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getTimeout(): float |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->timeout; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return int |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getMethod(): int |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->method; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return array<string, mixed> |
|
|
|
|
|
|
89
|
|
|
*/ |
|
90
|
|
|
public function getContextOptions(): array |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->contextOptions; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return resource |
|
97
|
|
|
*/ |
|
98
|
|
|
public function createContext() |
|
99
|
|
|
{ |
|
100
|
|
|
return \stream_context_create([ |
|
101
|
|
|
'ssl' => \array_merge( |
|
102
|
|
|
$this->contextOptions, |
|
103
|
|
|
['crypto_method' => $this->method] |
|
104
|
|
|
) |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.