generated from Nodarx/template
89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ProviderImap\Client;
|
|
|
|
use KTXM\ProviderImap\Client\Protocol\Response\GreetingResponse;
|
|
use KTXM\ProviderImap\Client\Transport\ConnectionInterface;
|
|
|
|
final class SessionContext
|
|
{
|
|
/** @var array<string, true> */
|
|
private array $capabilities = [];
|
|
private SessionState $state = SessionState::Disconnected;
|
|
private ?GreetingResponse $greeting = null;
|
|
private ?string $selectedMailbox = null;
|
|
|
|
public function __construct(
|
|
private readonly ConnectionConfig $config,
|
|
private readonly ConnectionInterface $connection,
|
|
) {}
|
|
|
|
public function config(): ConnectionConfig
|
|
{
|
|
return $this->config;
|
|
}
|
|
|
|
public function connection(): ConnectionInterface
|
|
{
|
|
return $this->connection;
|
|
}
|
|
|
|
public function state(): SessionState
|
|
{
|
|
return $this->state;
|
|
}
|
|
|
|
public function setState(SessionState $state): void
|
|
{
|
|
$this->state = $state;
|
|
}
|
|
|
|
public function greeting(): ?GreetingResponse
|
|
{
|
|
return $this->greeting;
|
|
}
|
|
|
|
public function setGreeting(GreetingResponse $greeting): void
|
|
{
|
|
$this->greeting = $greeting;
|
|
}
|
|
|
|
public function selectedMailbox(): ?string
|
|
{
|
|
return $this->selectedMailbox;
|
|
}
|
|
|
|
public function setSelectedMailbox(?string $selectedMailbox): void
|
|
{
|
|
$this->selectedMailbox = $selectedMailbox;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public function capabilities(): array
|
|
{
|
|
return array_keys($this->capabilities);
|
|
}
|
|
|
|
public function replaceCapabilities(string ...$capabilities): void
|
|
{
|
|
$this->capabilities = [];
|
|
|
|
foreach ($capabilities as $capability) {
|
|
$normalized = strtoupper(trim($capability));
|
|
if ($normalized === '') {
|
|
continue;
|
|
}
|
|
|
|
$this->capabilities[$normalized] = true;
|
|
}
|
|
}
|
|
|
|
public function hasCapability(string $capability): bool
|
|
{
|
|
return isset($this->capabilities[strtoupper($capability)]);
|
|
}
|
|
} |