feat: first impl
This commit is contained in:
28
src/StreamReadable.php
Normal file
28
src/StreamReadable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user