generated from Nodarx/template
88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ProviderImap\Client;
|
|
|
|
final class ConnectionConfig
|
|
{
|
|
public function __construct(
|
|
private readonly string $host,
|
|
private readonly int $port = 993,
|
|
private readonly ConnectionSecurity $security = ConnectionSecurity::Tls,
|
|
private readonly ?string $username = null,
|
|
private readonly ?string $password = null,
|
|
private readonly float $timeout = 30.0,
|
|
private readonly bool $verifyPeer = true,
|
|
private readonly bool $verifyPeerName = true,
|
|
private readonly bool $allowSelfSigned = false,
|
|
) {}
|
|
|
|
public function host(): string
|
|
{
|
|
return $this->host;
|
|
}
|
|
|
|
public function port(): int
|
|
{
|
|
return $this->port;
|
|
}
|
|
|
|
public function security(): ConnectionSecurity
|
|
{
|
|
return $this->security;
|
|
}
|
|
|
|
public function username(): ?string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function password(): ?string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function hasCredentials(): bool
|
|
{
|
|
return $this->username !== null && $this->password !== null;
|
|
}
|
|
|
|
public function timeout(): float
|
|
{
|
|
return $this->timeout;
|
|
}
|
|
|
|
public function verifyPeer(): bool
|
|
{
|
|
return $this->verifyPeer;
|
|
}
|
|
|
|
public function verifyPeerName(): bool
|
|
{
|
|
return $this->verifyPeerName;
|
|
}
|
|
|
|
public function allowSelfSigned(): bool
|
|
{
|
|
return $this->allowSelfSigned;
|
|
}
|
|
|
|
public function endpoint(): string
|
|
{
|
|
return sprintf('%s://%s:%d', $this->security->transport(), $this->host, $this->port);
|
|
}
|
|
|
|
public function streamContextOptions(): array
|
|
{
|
|
return [
|
|
'ssl' => [
|
|
'verify_peer' => $this->verifyPeer,
|
|
'verify_peer_name' => $this->verifyPeerName,
|
|
'allow_self_signed' => $this->allowSelfSigned,
|
|
'SNI_enabled' => true,
|
|
'peer_name' => $this->host,
|
|
],
|
|
];
|
|
}
|
|
} |