1 | <?php |
||
13 | class Port |
||
14 | { |
||
15 | const PROTOCOL_TCP = 'tcp'; |
||
16 | const PROTOCOL_UDP = 'udp'; |
||
17 | const PROTOCOL_SSL = 'ssl'; |
||
18 | const PROTOCOL_TLS = 'tls'; |
||
19 | |||
20 | /** @var string */ |
||
21 | protected $domain; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $protocol = self::PROTOCOL_TCP; |
||
25 | |||
26 | /** @var float */ |
||
27 | protected $timeout = 0.25; |
||
28 | |||
29 | /** @var array */ |
||
30 | protected $protocols = ['tcp', 'tls', 'udp', 'ssl']; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $defaultPorts = [ |
||
36 | 22 => 'tcp', |
||
37 | 80 => 'tcp', |
||
38 | 443 => 'tls', |
||
39 | 8080 => 'tcp', |
||
40 | 3306 => 'tcp', |
||
41 | ]; |
||
42 | |||
43 | /** @var array */ |
||
44 | protected $result = []; |
||
45 | |||
46 | /** @var array */ |
||
47 | protected $portsWithProtocol = []; |
||
48 | |||
49 | public static function for(string $domain): self |
||
53 | |||
54 | public function __construct(string $domain) |
||
58 | |||
59 | protected function sanitizeDomain(string $domain): string |
||
67 | |||
68 | public function getDomain(): string |
||
72 | |||
73 | public function getDefaultPorts(): array |
||
77 | |||
78 | public function getProtocols(): array |
||
82 | |||
83 | protected function addResult(int $port, string $protocol, bool $isOpen): void |
||
91 | |||
92 | /** |
||
93 | * @param array|int ...$ports |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | public function check(...$ports): array |
||
115 | |||
116 | protected function getUri(string $protocol): string |
||
120 | |||
121 | protected function checkPort(int $port, string $protocol): PromiseInterface |
||
137 | |||
138 | protected function checkNonUdpPort(int $port, string $protocol): bool |
||
151 | |||
152 | protected function checkUdpPort($port): bool |
||
186 | |||
187 | public function useTcp(): self |
||
193 | |||
194 | public function useTls(): self |
||
200 | |||
201 | public function useUdp(): self |
||
207 | |||
208 | public function useSsl(): self |
||
214 | |||
215 | public function setTimeout(float $seconds): self |
||
221 | |||
222 | protected function setProtocol(string $protocol): void |
||
226 | |||
227 | protected function addPortWithProtocol(int $port, string $protocol): void |
||
231 | |||
232 | protected function resolvePorts(array $ports = []): void |
||
257 | } |
||
258 |