| Total Complexity | 4 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class BlobEncode implements BinnValueEncoder |
||
| 10 | { |
||
| 11 | public const TYPE = Binn::BINN_STORAGE_BLOB; |
||
| 12 | |||
| 13 | public function encode($value): string |
||
| 14 | { |
||
| 15 | if (!$this->supportsEncoding($value)) { |
||
| 16 | throw new BinnException('Invalid value. Resource expected'); |
||
| 17 | } |
||
| 18 | |||
| 19 | $contents = ''; |
||
| 20 | |||
| 21 | while (!feof($value)) { |
||
| 22 | $contents .= fread($value, 1024); |
||
| 23 | } |
||
| 24 | |||
| 25 | $encodedType = Packer::packUint8(self::TYPE); |
||
| 26 | $encodedSize = Packer::packSize(strlen($encodedType) + strlen($contents), true); |
||
| 27 | |||
| 28 | return $encodedType . $encodedSize . $contents; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function supportsEncoding($value): bool |
||
| 34 | } |
||
| 35 | } |
||
| 36 |