Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DroppingStream.php

class DroppingStream

Stream decorator that begins dropping data once the size of the underlying stream becomes too full.

Hierarchy

  • class \GuzzleHttp\Psr7\DroppingStream implements \Psr\Http\Message\StreamInterface uses \GuzzleHttp\Psr7\StreamDecoratorTrait

Expanded class hierarchy of DroppingStream

File

vendor/guzzlehttp/psr7/src/DroppingStream.php, line 13

Namespace

GuzzleHttp\Psr7
View source
final class DroppingStream implements StreamInterface {
    use StreamDecoratorTrait;
    
    /** @var int */
    private $maxLength;
    
    /** @var StreamInterface */
    private $stream;
    
    /**
     * @param StreamInterface $stream    Underlying stream to decorate.
     * @param int             $maxLength Maximum size before dropping data.
     */
    public function __construct(StreamInterface $stream, int $maxLength) {
        $this->stream = $stream;
        $this->maxLength = $maxLength;
    }
    public function write($string) : int {
        $diff = $this->maxLength - $this->stream
            ->getSize();
        // Begin returning 0 when the underlying stream is too large.
        if ($diff <= 0) {
            return 0;
        }
        // Write the stream or a subset of the stream if needed.
        if (strlen($string) < $diff) {
            return $this->stream
                ->write($string);
        }
        return $this->stream
            ->write(substr($string, 0, $diff));
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DroppingStream::$maxLength private property @var int
DroppingStream::$stream private property @var StreamInterface
DroppingStream::write public function Write data to the stream. Overrides StreamDecoratorTrait::write
DroppingStream::__construct public function Overrides StreamDecoratorTrait::__construct
StreamDecoratorTrait::close public function 1
StreamDecoratorTrait::createStream protected function Implement in subclasses to dynamically create streams when requested. 2
StreamDecoratorTrait::detach public function
StreamDecoratorTrait::eof public function 2
StreamDecoratorTrait::getContents public function
StreamDecoratorTrait::getMetadata public function
StreamDecoratorTrait::getSize public function 2
StreamDecoratorTrait::isReadable public function
StreamDecoratorTrait::isSeekable public function 1
StreamDecoratorTrait::isWritable public function 1
StreamDecoratorTrait::read public function 2
StreamDecoratorTrait::rewind public function 1
StreamDecoratorTrait::seek public function 3
StreamDecoratorTrait::tell public function 1
StreamDecoratorTrait::__call public function Allow decorators to implement custom methods
StreamDecoratorTrait::__get public function Magic method used to create a new stream if streams are not added in
the constructor of a decorator (e.g., LazyOpenStream).
StreamDecoratorTrait::__toString public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal