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

StreamDecoratorTrait.php

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


001  <?php
002   
003  namespace GuzzleHttp\Psr7;
004   
005  use Psr\Http\Message\StreamInterface;
006   
007  /**
008   * Stream decorator trait
009   *
010   * @property StreamInterface stream
011   */
012  trait StreamDecoratorTrait
013  {
014      /**
015       * @param StreamInterface $stream Stream to decorate
016       */
017      public function __construct(StreamInterface $stream)
018      {
019          $this->stream = $stream;
020      }
021   
022      /**
023       * Magic method used to create a new stream if streams are not added in
024       * the constructor of a decorator (e.g., LazyOpenStream).
025       *
026       * @param string $name Name of the property (allows "stream" only).
027       *
028       * @return StreamInterface
029       */
030      public function __get($name)
031      {
032          if ($name == 'stream') {
033              $this->stream = $this->createStream();
034              return $this->stream;
035          }
036   
037          throw new \UnexpectedValueException("$name not found on class");
038      }
039   
040      public function __toString()
041      {
042          try {
043              if ($this->isSeekable()) {
044                  $this->seek(0);
045              }
046              return $this->getContents();
047          } catch (\Exception $e) {
048              // Really, PHP? https://bugs.php.net/bug.php?id=53648
049              trigger_error('StreamDecorator::__toString exception: '
050                  . (string) $e, E_USER_ERROR);
051              return '';
052          }
053      }
054   
055      public function getContents()
056      {
057          return Utils::copyToString($this);
058      }
059   
060      /**
061       * Allow decorators to implement custom methods
062       *
063       * @param string $method Missing method name
064       * @param array  $args   Method arguments
065       *
066       * @return mixed
067       */
068      public function __call($method, array $args)
069      {
070          $result = call_user_func_array([$this->stream, $method], $args);
071   
072          // Always return the wrapped object if the result is a return $this
073          return $result === $this->stream ? $this : $result;
074      }
075   
076      public function close()
077      {
078          $this->stream->close();
079      }
080   
081      public function getMetadata($key = null)
082      {
083          return $this->stream->getMetadata($key);
084      }
085   
086      public function detach()
087      {
088          return $this->stream->detach();
089      }
090   
091      public function getSize()
092      {
093          return $this->stream->getSize();
094      }
095   
096      public function eof()
097      {
098          return $this->stream->eof();
099      }
100   
101      public function tell()
102      {
103          return $this->stream->tell();
104      }
105   
106      public function isReadable()
107      {
108          return $this->stream->isReadable();
109      }
110   
111      public function isWritable()
112      {
113          return $this->stream->isWritable();
114      }
115   
116      public function isSeekable()
117      {
118          return $this->stream->isSeekable();
119      }
120   
121      public function rewind()
122      {
123          $this->seek(0);
124      }
125   
126      public function seek($offset, $whence = SEEK_SET)
127      {
128          $this->stream->seek($offset, $whence);
129      }
130   
131      public function read($length)
132      {
133          return $this->stream->read($length);
134      }
135   
136      public function write($string)
137      {
138          return $this->stream->write($string);
139      }
140   
141      /**
142       * Implement in subclasses to dynamically create streams when requested.
143       *
144       * @return StreamInterface
145       *
146       * @throws \BadMethodCallException
147       */
148      protected function createStream()
149      {
150          throw new \BadMethodCallException('Not implemented');
151      }
152  }
153