PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / spomky-labs / cbor-php / src / TextStringWithChunkObject.php

TextStringWithChunkObject.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/spomky-labs/cbor-php/src/TextStringWithChunkObject.php

88 lines 1.8 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
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2018-2020 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 CBOR;
15
16 use InvalidArgumentException;
17
18 final class TextStringWithChunkObject extends AbstractCBORObject
19 {
20 private const MAJOR_TYPE = 0b011;
21 private const ADDITIONAL_INFORMATION = 0b00011111;
22
23 /**
24 * @var TextStringObject[]
25 */
26 private $data = [];
27
28 public function __construct()
29 {
30 parent::__construct(self::MAJOR_TYPE, self::ADDITIONAL_INFORMATION);
31 }
32
33 public function __toString(): string
34 {
35 $result = parent::__toString();
36 foreach ($this->data as $object) {
37 $result .= (string) $object;
38 }
39 $bin = hex2bin('FF');
40 if (false === $bin) {
41 throw new InvalidArgumentException('Unable to convert the data');
42 }
43 $result .= $bin;
44
45 return $result;
46 }
47
48 public function add(TextStringObject $chunk): void
49 {
50 $this->data[] = $chunk;
51 }
52
53 public function append(string $chunk): void
54 {
55 $this->add(new TextStringObject($chunk));
56 }
57
58 public function getValue(): string
59 {
60 $result = '';
61 foreach ($this->data as $object) {
62 $result .= $object->getValue();
63 }
64
65 return $result;
66 }
67
68 public function getLength(): int
69 {
70 $length = 0;
71 foreach ($this->data as $object) {
72 $length += $object->getLength();
73 }
74
75 return $length;
76 }
77
78 public function getNormalizedData(bool $ignoreTags = false): string
79 {
80 $result = '';
81 foreach ($this->data as $object) {
82 $result .= $object->getNormalizedData($ignoreTags);
83 }
84
85 return $result;
86 }
87 }
88