Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
BufferStream.php
001 <?php
002 namespace GuzzleHttp\Stream;
003
004 use GuzzleHttp\Stream\Exception\CannotAttachException;
005
006 /**
007 * Provides a buffer stream that can be written to to fill a buffer, and read
008 * from to remove bytes from the buffer.
009 *
010 * This stream returns a "hwm" metadata value that tells upstream consumers
011 * what the configured high water mark of the stream is, or the maximum
012 * preferred size of the buffer.
013 *
014 * @package GuzzleHttp\Stream
015 */
016 class BufferStream implements StreamInterface
017 {
018 private $hwm;
019 private $buffer = '';
020
021 /**
022 * @param int $hwm High water mark, representing the preferred maximum
023 * buffer size. If the size of the buffer exceeds the high
024 * water mark, then calls to write will continue to succeed
025 * but will return false to inform writers to slow down
026 * until the buffer has been drained by reading from it.
027 */
028 public function __construct($hwm = 16384)
029 {
030 $this->hwm = $hwm;
031 }
032
033 public function __toString()
034 {
035 return $this->getContents();
036 }
037
038 public function getContents()
039 {
040 $buffer = $this->buffer;
041 $this->buffer = '';
042
043 return $buffer;
044 }
045
046 public function close()
047 {
048 $this->buffer = '';
049 }
050
051 public function detach()
052 {
053 $this->close();
054 }
055
056 public function attach($stream)
057 {
058 throw new CannotAttachException();
059 }
060
061 public function getSize()
062 {
063 return strlen($this->buffer);
064 }
065
066 public function isReadable()
067 {
068 return true;
069 }
070
071 public function isWritable()
072 {
073 return true;
074 }
075
076 public function isSeekable()
077 {
078 return false;
079 }
080
081 public function seek($offset, $whence = SEEK_SET)
082 {
083 return false;
084 }
085
086 public function eof()
087 {
088 return strlen($this->buffer) === 0;
089 }
090
091 public function tell()
092 {
093 return false;
094 }
095
096 /**
097 * Reads data from the buffer.
098 */
099 public function read($length)
100 {
101 $currentLength = strlen($this->buffer);
102
103 if ($length >= $currentLength) {
104 // No need to slice the buffer because we don't have enough data.
105 $result = $this->buffer;
106 $this->buffer = '';
107 } else {
108 // Slice up the result to provide a subset of the buffer.
109 $result = substr($this->buffer, 0, $length);
110 $this->buffer = substr($this->buffer, $length);
111 }
112
113 return $result;
114 }
115
116 /**
117 * Writes data to the buffer.
118 */
119 public function write($string)
120 {
121 $this->buffer .= $string;
122
123 if (strlen($this->buffer) >= $this->hwm) {
124 return false;
125 }
126
127 return strlen($string);
128 }
129
130 public function getMetadata($key = null)
131 {
132 if ($key == 'hwm') {
133 return $this->hwm;
134 }
135
136 return $key ? null : [];
137 }
138 }
139