[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2019 Spomky-Labs 9 * 10 * This software may be modified and distributed under the terms 11 * of the MIT license. See the LICENSE file for details. 12 */ 13 14 namespace Webauthn; 15 16 use Assert\Assertion; 17 use CBOR\Stream; 18 19 final class StringStream implements Stream 20 { 21 /** 22 * @var resource 23 */ 24 private $data; 25 26 /** 27 * @var int 28 */ 29 private $length; 30 31 /** 32 * @var int 33 */ 34 private $totalRead = 0; 35 36 public function __construct(string $data) 37 { 38 $this->length = mb_strlen($data, '8bit'); 39 $resource = fopen('php://memory', 'rb+'); 40 Assertion::isResource($resource, 'Unable to open memory'); 41 $result = fwrite($resource, $data); 42 Assertion::integer($result, 'Unable to write memory'); 43 $result = rewind($resource); 44 Assertion::true($result, 'Unable to read memory'); 45 $this->data = $resource; 46 } 47 48 public function read(int $length): string 49 { 50 if (0 === $length) { 51 return ''; 52 } 53 $read = fread($this->data, $length); 54 Assertion::string($read, 'Unable to read memory'); 55 $bytesRead = mb_strlen($read, '8bit'); 56 Assertion::length($read, $length, sprintf('Out of range. Expected: %d, read: %d.', $length, $bytesRead), null, '8bit'); 57 $this->totalRead += $bytesRead; 58 59 return $read; 60 } 61 62 public function close(): void 63 { 64 $result = fclose($this->data); 65 Assertion::true($result, 'Unable to close the memory'); 66 } 67 68 public function isEOF(): bool 69 { 70 return $this->totalRead === $this->length; 71 } 72 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |