PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / DroppingStream.php

DroppingStream.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at vendor_prefixed/guzzlehttp/psr7/src/DroppingStream.php

44 lines 1.5 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 YoastSEO_Vendor\GuzzleHttp\Psr7;
5
6 use YoastSEO_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 \YoastSEO_Vendor\Psr\Http\Message\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(\YoastSEO_Vendor\Psr\Http\Message\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 \YoastSEO_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