generated from Nodarx/template
feat: initial version
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
50
lib/Client/Protocol/Response/ResponseBuilder.php
Normal file
50
lib/Client/Protocol/Response/ResponseBuilder.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Protocol\Response;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Gricob\IMAP\Protocol\Response\Line\Line;
|
||||
use Gricob\IMAP\Protocol\Response\Line\Status\Status;
|
||||
|
||||
class ResponseBuilder
|
||||
{
|
||||
private ?Status $status = null;
|
||||
|
||||
/**
|
||||
* @var list<Line>
|
||||
*/
|
||||
private array $data = [];
|
||||
|
||||
public function __construct(private readonly string $statusTag)
|
||||
{
|
||||
}
|
||||
|
||||
public function addLine(Line $line): void
|
||||
{
|
||||
if ($line instanceof Status && $line->tag === $this->statusTag) {
|
||||
$this->status = $line;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data[] = $line;
|
||||
}
|
||||
|
||||
public function hasStatus(): bool
|
||||
{
|
||||
return $this->status !== null;
|
||||
}
|
||||
|
||||
public function build(): Response
|
||||
{
|
||||
if (null === $this->status) {
|
||||
throw new BadMethodCallException();
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$this->status,
|
||||
$this->data,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user