Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

PumpStream.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.99 KiB


001  <?php
002   
003  namespace GuzzleHttp\Psr7;
004   
005  use Psr\Http\Message\StreamInterface;
006   
007  /**
008   * Provides a read only stream that pumps data from a PHP callable.
009   *
010   * When invoking the provided callable, the PumpStream will pass the amount of
011   * data requested to read to the callable. The callable can choose to ignore
012   * this value and return fewer or more bytes than requested. Any extra data
013   * returned by the provided callable is buffered internally until drained using
014   * the read() function of the PumpStream. The provided callable MUST return
015   * false when there is no more data to read.
016   *
017   * @final
018   */
019  class PumpStream implements StreamInterface
020  {
021      /** @var callable */
022      private $source;
023   
024      /** @var int */
025      private $size;
026   
027      /** @var int */
028      private $tellPos = 0;
029   
030      /** @var array */
031      private $metadata;
032   
033      /** @var BufferStream */
034      private $buffer;
035   
036      /**
037       * @param callable $source  Source of the stream data. The callable MAY
038       *                          accept an integer argument used to control the
039       *                          amount of data to return. The callable MUST
040       *                          return a string when called, or false on error
041       *                          or EOF.
042       * @param array    $options Stream options:
043       *                          - metadata: Hash of metadata to use with stream.
044       *                          - size: Size of the stream, if known.
045       */
046      public function __construct(callable $source, array $options = [])
047      {
048          $this->source = $source;
049          $this->size = isset($options['size']) ? $options['size'] : null;
050          $this->metadata = isset($options['metadata']) ? $options['metadata'] : [];
051          $this->buffer = new BufferStream();
052      }
053   
054      public function __toString()
055      {
056          try {
057              return Utils::copyToString($this);
058          } catch (\Exception $e) {
059              return '';
060          }
061      }
062   
063      public function close()
064      {
065          $this->detach();
066      }
067   
068      public function detach()
069      {
070          $this->tellPos = false;
071          $this->source = null;
072   
073          return null;
074      }
075   
076      public function getSize()
077      {
078          return $this->size;
079      }
080   
081      public function tell()
082      {
083          return $this->tellPos;
084      }
085   
086      public function eof()
087      {
088          return !$this->source;
089      }
090   
091      public function isSeekable()
092      {
093          return false;
094      }
095   
096      public function rewind()
097      {
098          $this->seek(0);
099      }
100   
101      public function seek($offset, $whence = SEEK_SET)
102      {
103          throw new \RuntimeException('Cannot seek a PumpStream');
104      }
105   
106      public function isWritable()
107      {
108          return false;
109      }
110   
111      public function write($string)
112      {
113          throw new \RuntimeException('Cannot write to a PumpStream');
114      }
115   
116      public function isReadable()
117      {
118          return true;
119      }
120   
121      public function read($length)
122      {
123          $data = $this->buffer->read($length);
124          $readLen = strlen($data);
125          $this->tellPos += $readLen;
126          $remaining = $length - $readLen;
127   
128          if ($remaining) {
129              $this->pump($remaining);
130              $data .= $this->buffer->read($remaining);
131              $this->tellPos += strlen($data) - $readLen;
132          }
133   
134          return $data;
135      }
136   
137      public function getContents()
138      {
139          $result = '';
140          while (!$this->eof()) {
141              $result .= $this->read(1000000);
142          }
143   
144          return $result;
145      }
146   
147      public function getMetadata($key = null)
148      {
149          if (!$key) {
150              return $this->metadata;
151          }
152   
153          return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
154      }
155   
156      private function pump($length)
157      {
158          if ($this->source) {
159              do {
160                  $data = call_user_func($this->source, $length);
161                  if ($data === false || $data === null) {
162                      $this->source = null;
163                      return;
164                  }
165                  $this->buffer->write($data);
166                  $length -= strlen($data);
167              } while ($length > 0);
168          }
169      }
170  }
171