PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / guzzlehttp / psr7 / src / BufferStream.php
ameliabooking / vendor / guzzlehttp / psr7 / src Last commit date
AppendStream.php 3 years ago BufferStream.php 3 years ago CachingStream.php 3 years ago DroppingStream.php 3 years ago FnStream.php 3 years ago Header.php 5 years ago InflateStream.php 3 years ago LazyOpenStream.php 3 years ago LimitStream.php 3 years ago Message.php 3 years ago MessageTrait.php 2 years ago MimeType.php 5 years ago MultipartStream.php 3 years ago NoSeekStream.php 3 years ago PumpStream.php 3 years ago Query.php 4 years ago Request.php 3 years ago Response.php 3 years ago Rfc7230.php 4 years ago ServerRequest.php 3 years ago Stream.php 3 years ago StreamDecoratorTrait.php 3 years ago StreamWrapper.php 3 years ago UploadedFile.php 3 years ago Uri.php 3 years ago UriComparator.php 2 years ago UriNormalizer.php 3 years ago UriResolver.php 3 years ago Utils.php 3 years ago functions.php 3 years ago functions_include.php 5 years ago
BufferStream.php
143 lines
1 <?php
2
3 namespace AmeliaGuzzleHttp\Psr7;
4
5 use AmeliaPsr\Http\Message\StreamInterface;
6
7 /**
8 * Provides a buffer stream that can be written to to fill a buffer, and read
9 * from to remove bytes from the buffer.
10 *
11 * This stream returns a "hwm" metadata value that tells upstream consumers
12 * what the configured high water mark of the stream is, or the maximum
13 * preferred size of the buffer.
14 *
15 * @final
16 */
17 class BufferStream implements StreamInterface
18 {
19 private $hwm;
20 private $buffer = '';
21
22 /**
23 * @param int $hwm High water mark, representing the preferred maximum
24 * buffer size. If the size of the buffer exceeds the high
25 * water mark, then calls to write will continue to succeed
26 * but will return false to inform writers to slow down
27 * until the buffer has been drained by reading from it.
28 */
29 public function __construct($hwm = 16384)
30 {
31 $this->hwm = $hwm;
32 }
33
34 public function __toString()
35 {
36 return $this->getContents();
37 }
38
39 public function getContents()
40 {
41 $buffer = $this->buffer;
42 $this->buffer = '';
43
44 return $buffer;
45 }
46
47 public function close()
48 {
49 $this->buffer = '';
50 }
51
52 public function detach()
53 {
54 $this->close();
55
56 return null;
57 }
58
59 public function getSize()
60 {
61 return strlen($this->buffer);
62 }
63
64 public function isReadable()
65 {
66 return true;
67 }
68
69 public function isWritable()
70 {
71 return true;
72 }
73
74 public function isSeekable()
75 {
76 return false;
77 }
78
79 public function rewind()
80 {
81 $this->seek(0);
82 }
83
84 public function seek($offset, $whence = SEEK_SET)
85 {
86 throw new \RuntimeException('Cannot seek a BufferStream');
87 }
88
89 public function eof()
90 {
91 return strlen($this->buffer) === 0;
92 }
93
94 public function tell()
95 {
96 throw new \RuntimeException('Cannot determine the position of a BufferStream');
97 }
98
99 /**
100 * Reads data from the buffer.
101 */
102 public function read($length)
103 {
104 $currentLength = strlen($this->buffer);
105
106 if ($length >= $currentLength) {
107 // No need to slice the buffer because we don't have enough data.
108 $result = $this->buffer;
109 $this->buffer = '';
110 } else {
111 // Slice up the result to provide a subset of the buffer.
112 $result = substr($this->buffer, 0, $length);
113 $this->buffer = substr($this->buffer, $length);
114 }
115
116 return $result;
117 }
118
119 /**
120 * Writes data to the buffer.
121 */
122 public function write($string)
123 {
124 $this->buffer .= $string;
125
126 // TODO: What should happen here?
127 if (strlen($this->buffer) >= $this->hwm) {
128 return false;
129 }
130
131 return strlen($string);
132 }
133
134 public function getMetadata($key = null)
135 {
136 if ($key == 'hwm') {
137 return $this->hwm;
138 }
139
140 return $key ? null : [];
141 }
142 }
143