PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.2
Defender Security – Malware Scanner, Login Security & Firewall v5.7.2
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 / IndefiniteLengthTextStringObject.php

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

107 lines 2.2 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 /**
17 * @final
18 */
19 class IndefiniteLengthTextStringObject extends AbstractCBORObject implements Normalizable
20 {
21 private const MAJOR_TYPE = self::MAJOR_TYPE_TEXT_STRING;
22
23 private const ADDITIONAL_INFORMATION = self::LENGTH_INDEFINITE;
24
25 /**
26 * @var TextStringObject[]
27 */
28 private $data = [];
29
30 public function __construct()
31 {
32 parent::__construct(self::MAJOR_TYPE, self::ADDITIONAL_INFORMATION);
33 }
34
35 public function __toString(): string
36 {
37 $result = parent::__toString();
38 foreach ($this->data as $object) {
39 $result .= (string) $object;
40 }
41
42 return $result . "\xFF";
43 }
44
45 public static function create(): self
46 {
47 return new self();
48 }
49
50 public function add(TextStringObject $chunk): self
51 {
52 $this->data[] = $chunk;
53
54 return $this;
55 }
56
57 public function append(string $chunk): self
58 {
59 $this->add(TextStringObject::create($chunk));
60
61 return $this;
62 }
63
64 public function getValue(): string
65 {
66 $result = '';
67 foreach ($this->data as $object) {
68 $result .= $object->getValue();
69 }
70
71 return $result;
72 }
73
74 public function getLength(): int
75 {
76 $length = 0;
77 foreach ($this->data as $object) {
78 $length += $object->getLength();
79 }
80
81 return $length;
82 }
83
84 public function normalize(): string
85 {
86 $result = '';
87 foreach ($this->data as $object) {
88 $result .= $object->normalize();
89 }
90
91 return $result;
92 }
93
94 /**
95 * @deprecated The method will be removed on v3.0. Please rely on the CBOR\Normalizable interface
96 */
97 public function getNormalizedData(bool $ignoreTags = false): string
98 {
99 $result = '';
100 foreach ($this->data as $object) {
101 $result .= $object->getNormalizedData($ignoreTags);
102 }
103
104 return $result;
105 }
106 }
107