File: SmallChunksStream.php

package info (click to toggle)
php-slim 3.12.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: php: 11,581; makefile: 18; xml: 10; sh: 3
file content (127 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
 * Slim Framework (https://slimframework.com)
 *
 * @license https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
 */

namespace Slim\Tests\Mocks;

use Exception;
use Psr\Http\Message\StreamInterface;

class SmallChunksStream implements StreamInterface
{
    const CHUNK_SIZE = 10;
    const SIZE = 40;

    /**
     * @var int
     */
    private $amountToRead;

    public function __construct()
    {
        $this->amountToRead = self::SIZE;
    }

    /**
     * @throws Exception
     */
    public function __toString()
    {
        throw new Exception('not implemented');
    }

    public function close()
    {
    }

    /**
     * @throws Exception
     */
    public function detach()
    {
        throw new Exception('not implemented');
    }

    public function eof()
    {
        return $this->amountToRead === 0;
    }

    /**
     * @throws Exception
     */
    public function getContents()
    {
        throw new Exception('not implemented');
    }

    /**
     * @param string $key
     *
     * @throws Exception
     */
    public function getMetadata($key = null)
    {
        throw new Exception('not implemented');
    }

    public function getSize()
    {
        return self::SIZE;
    }

    public function isReadable()
    {
        return true;
    }

    public function isSeekable()
    {
        return false;
    }

    public function isWritable()
    {
        return false;
    }

    public function read($length)
    {
        $size = min($this->amountToRead, self::CHUNK_SIZE, $length);
        $this->amountToRead -= $size;

        return str_repeat('.', min($length, $size));
    }

    /**
     * @throws Exception
     */
    public function rewind()
    {
        throw new Exception('not implemented');
    }

    /**
     * @throws Exception
     */
    public function seek($offset, $whence = SEEK_SET)
    {
        throw new Exception('not implemented');
    }

    /**
     * @throws Exception
     */
    public function tell()
    {
        throw new Exception('not implemented');
    }

    public function write($string)
    {
        return strlen($string);
    }
}