feat: first impl

This commit is contained in:
2025-08-16 21:48:01 +02:00
parent e60ab9d7bc
commit 209c910f33
14 changed files with 444 additions and 0 deletions

28
src/StreamReadable.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Nih\CommandBuilder;
trait StreamReadable
{
/**
* @param resource $stream
*/
public function __construct(private $stream)
{
}
public function read(int $length): ?string
{
return fread($this->stream, $length) ?: null;
}
public function getContents(?int $length = null, int $offset = -1): ?string
{
$contents = stream_get_contents($this->stream, $length, $offset);
return $contents === false
? null
: $contents;
}
}