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

FnStream.php

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


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