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

FnStream.php

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


001  <?php
002   
003  namespace GuzzleHttp\Psr7;
004   
005  use Psr\Http\Message\StreamInterface;
006   
007  /**
008   * Compose stream implementations based on a hash of functions.
009   *
010   * Allows for easy testing and extension of a provided stream without needing
011   * to create a concrete class for a simple extension point.
012   *
013   * @final
014   */
015  class FnStream implements StreamInterface
016  {
017      /** @var array */
018      private $methods;
019   
020      /** @var array Methods that must be implemented in the given array */
021      private static $slots = ['__toString', 'close', 'detach', 'rewind',
022          'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
023          'isReadable', 'read', 'getContents', 'getMetadata'];
024   
025      /**
026       * @param array $methods Hash of method name to a callable.
027       */
028      public function __construct(array $methods)
029      {
030          $this->methods = $methods;
031   
032          // Create the functions on the class
033          foreach ($methods as $name => $fn) {
034              $this->{'_fn_' . $name} = $fn;
035          }
036      }
037   
038      /**
039       * Lazily determine which methods are not implemented.
040       *
041       * @throws \BadMethodCallException
042       */
043      public function __get($name)
044      {
045          throw new \BadMethodCallException(str_replace('_fn_', '', $name)
046              . '() is not implemented in the FnStream');
047      }
048   
049      /**
050       * The close method is called on the underlying stream only if possible.
051       */
052      public function __destruct()
053      {
054          if (isset($this->_fn_close)) {
055              call_user_func($this->_fn_close);
056          }
057      }
058   
059      /**
060       * An unserialize would allow the __destruct to run when the unserialized value goes out of scope.
061       *
062       * @throws \LogicException
063       */
064      public function __wakeup()
065      {
066          throw new \LogicException('FnStream should never be unserialized');
067      }
068   
069      /**
070       * Adds custom functionality to an underlying stream by intercepting
071       * specific method calls.
072       *
073       * @param StreamInterface $stream  Stream to decorate
074       * @param array           $methods Hash of method name to a closure
075       *
076       * @return FnStream
077       */
078      public static function decorate(StreamInterface $stream, array $methods)
079      {
080          // If any of the required methods were not provided, then simply
081          // proxy to the decorated stream.
082          foreach (array_diff(self::$slots, array_keys($methods)) as $diff) {
083              $methods[$diff] = [$stream, $diff];
084          }
085   
086          return new self($methods);
087      }
088   
089      public function __toString()
090      {
091          return call_user_func($this->_fn___toString);
092      }
093   
094      public function close()
095      {
096          return call_user_func($this->_fn_close);
097      }
098   
099      public function detach()
100      {
101          return call_user_func($this->_fn_detach);
102      }
103   
104      public function getSize()
105      {
106          return call_user_func($this->_fn_getSize);
107      }
108   
109      public function tell()
110      {
111          return call_user_func($this->_fn_tell);
112      }
113   
114      public function eof()
115      {
116          return call_user_func($this->_fn_eof);
117      }
118   
119      public function isSeekable()
120      {
121          return call_user_func($this->_fn_isSeekable);
122      }
123   
124      public function rewind()
125      {
126          call_user_func($this->_fn_rewind);
127      }
128   
129      public function seek($offset, $whence = SEEK_SET)
130      {
131          call_user_func($this->_fn_seek, $offset, $whence);
132      }
133   
134      public function isWritable()
135      {
136          return call_user_func($this->_fn_isWritable);
137      }
138   
139      public function write($string)
140      {
141          return call_user_func($this->_fn_write, $string);
142      }
143   
144      public function isReadable()
145      {
146          return call_user_func($this->_fn_isReadable);
147      }
148   
149      public function read($length)
150      {
151          return call_user_func($this->_fn_read, $length);
152      }
153   
154      public function getContents()
155      {
156          return call_user_func($this->_fn_getContents);
157      }
158   
159      public function getMetadata($key = null)
160      {
161          return call_user_func($this->_fn_getMetadata, $key);
162      }
163  }
164