woocommerce-pos
/
vendor_prefixed
/
sentry
/
sentry
/
src
/
DataCollection
/
InMemoryHttpBodySource.php
InMemoryHttpBodySource.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.27, at vendor_prefixed/sentry/sentry/src/DataCollection/InMemoryHttpBodySource.php
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WCPOS\Vendor\Sentry\DataCollection; |
| 5 | |
| 6 | /** |
| 7 | * @internal |
| 8 | */ |
| 9 | final class InMemoryHttpBodySource implements HttpBodySourceInterface |
| 10 | { |
| 11 | /** |
| 12 | * @var array<array-key, mixed>|string|null |
| 13 | */ |
| 14 | private $body; |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | private $contentType; |
| 19 | /** |
| 20 | * @var int|null |
| 21 | */ |
| 22 | private $bodyLength; |
| 23 | /** |
| 24 | * @param mixed $body |
| 25 | */ |
| 26 | public function __construct($body, string $contentType = '', ?int $bodyLength = null) |
| 27 | { |
| 28 | $this->body = \is_array($body) || \is_string($body) ? $body : null; |
| 29 | $this->contentType = $contentType; |
| 30 | $this->bodyLength = $bodyLength; |
| 31 | } |
| 32 | public function getKnownLength() : ?int |
| 33 | { |
| 34 | return \is_string($this->body) ? \max(\strlen($this->body), $this->bodyLength ?? 0) : $this->bodyLength; |
| 35 | } |
| 36 | public function getContentType() : string |
| 37 | { |
| 38 | return $this->contentType; |
| 39 | } |
| 40 | /** |
| 41 | * {@inheritdoc} |
| 42 | */ |
| 43 | public function read(int $limit) |
| 44 | { |
| 45 | return $this->body; |
| 46 | } |
| 47 | } |
| 48 |