PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / guzzlehttp / psr7 / src / DroppingStream.php

DroppingStream.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/guzzlehttp/psr7/src/DroppingStream.php

44 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace Metricool\Vendor\GuzzleHttp\Psr7;
5
6 use Metricool\Vendor\Psr\Http\Message\StreamInterface;
7 /**
8 * Stream decorator that begins dropping data once the size of the underlying
9 * stream becomes too full.
10 */
11 final class DroppingStream implements StreamInterface
12 {
13 use StreamDecoratorTrait;
14 /** @var int */
15 private $maxLength;
16 /** @var StreamInterface */
17 private $stream;
18 /**
19 * @param StreamInterface $stream Underlying stream to decorate.
20 * @param int $maxLength Maximum size before dropping data.
21 */
22 public function __construct(StreamInterface $stream, int $maxLength)
23 {
24 $this->stream = $stream;
25 $this->maxLength = $maxLength;
26 }
27 public function write($string): int
28 {
29 if (!\is_string($string)) {
30 \Metricool\Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.', \get_debug_type($string));
31 }
32 $diff = $this->maxLength - $this->stream->getSize();
33 // Begin returning 0 when the underlying stream is too large.
34 if ($diff <= 0) {
35 return 0;
36 }
37 // Write the stream or a subset of the stream if needed.
38 if (strlen($string) < $diff) {
39 return $this->stream->write($string);
40 }
41 return $this->stream->write(substr($string, 0, $diff));
42 }
43 }
44