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

StreamDecoratorTrait.php

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


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