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

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

GuzzleStreamWrapper.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 2.70 KiB


 001  <?php
 002  namespace GuzzleHttp\Stream;
 003   
 004  /**
 005   * Converts Guzzle streams into PHP stream resources.
 006   */
 007  class GuzzleStreamWrapper
 008  {
 009      /** @var resource */
 010      public $context;
 011   
 012      /** @var StreamInterface */
 013      private $stream;
 014   
 015      /** @var string r, r+, or w */
 016      private $mode;
 017   
 018      /**
 019       * Returns a resource representing the stream.
 020       *
 021       * @param StreamInterface $stream The stream to get a resource for
 022       *
 023       * @return resource
 024       * @throws \InvalidArgumentException if stream is not readable or writable
 025       */
 026      public static function getResource(StreamInterface $stream)
 027      {
 028          self::register();
 029   
 030          if ($stream->isReadable()) {
 031              $mode = $stream->isWritable() ? 'r+' : 'r';
 032          } elseif ($stream->isWritable()) {
 033              $mode = 'w';
 034          } else {
 035              throw new \InvalidArgumentException('The stream must be readable, '
 036                  . 'writable, or both.');
 037          }
 038   
 039          return fopen('guzzle://stream', $mode, null, stream_context_create([
 040              'guzzle' => ['stream' => $stream]
 041          ]));
 042      }
 043   
 044      /**
 045       * Registers the stream wrapper if needed
 046       */
 047      public static function register()
 048      {
 049          if (!in_array('guzzle', stream_get_wrappers())) {
 050              stream_wrapper_register('guzzle', __CLASS__);
 051          }
 052      }
 053   
 054      public function stream_open($path, $mode, $options, &$opened_path)
 055      {
 056          $options = stream_context_get_options($this->context);
 057   
 058          if (!isset($options['guzzle']['stream'])) {
 059              return false;
 060          }
 061   
 062          $this->mode = $mode;
 063          $this->stream = $options['guzzle']['stream'];
 064   
 065          return true;
 066      }
 067   
 068      public function stream_read($count)
 069      {
 070          return $this->stream->read($count);
 071      }
 072   
 073      public function stream_write($data)
 074      {
 075          return (int) $this->stream->write($data);
 076      }
 077   
 078      public function stream_tell()
 079      {
 080          return $this->stream->tell();
 081      }
 082   
 083      public function stream_eof()
 084      {
 085          return $this->stream->eof();
 086      }
 087   
 088      public function stream_seek($offset, $whence)
 089      {
 090          return $this->stream->seek($offset, $whence);
 091      }
 092   
 093      public function stream_stat()
 094      {
 095          static $modeMap = [
 096              'r'  => 33060,
 097              'r+' => 33206,
 098              'w'  => 33188
 099          ];
 100   
 101          return [
 102              'dev'     => 0,
 103              'ino'     => 0,
 104              'mode'    => $modeMap[$this->mode],
 105              'nlink'   => 0,
 106              'uid'     => 0,
 107              'gid'     => 0,
 108              'rdev'    => 0,
 109              'size'    => $this->stream->getSize() ?: 0,
 110              'atime'   => 0,
 111              'mtime'   => 0,
 112              'ctime'   => 0,
 113              'blksize' => 0,
 114              'blocks'  => 0
 115          ];
 116      }
 117  }
 118