~ancarda/psr7-string-stream

ref: 415624673042e8093e1d8ff161baa20473bc4d48 psr7-string-stream/src/ReadOnlyStringStream.php -rw-r--r-- 685 bytes
41562467Mark Dain Introduce ReadOnlyStringStream 1 year, 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

declare(strict_types=1);

namespace Ancarda\Psr7\StringStream;

use RuntimeException;

/**
 * String based PSR-7 Stream that cannot be written to, only read and seeked
 */
class ReadOnlyStringStream extends StringStream
{
    /**
     * Returns false as this stream is read only
     *
     * @return bool
     */
    public function isWritable(): bool
    {
        return false;
    }

    /**
     * Throws a RuntimeException as this stream is read only
     *
     * @param string $string
     * @throws RuntimeException
     * @return int
     */
    public function write($string): int
    {
        throw new RuntimeException('Cannot write(): Read Only Stream');
    }
}