Debian Codegraph @

lib/3rdParty/composer/spomky-labs/cbor-php/src/TextStringObject.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CBOR;
6
7 /**
8 * @see \CBOR\Test\TextStringObjectTest
9 */
10 final class TextStringObject extends AbstractCBORObject implements Normalizable
11 {
12 private const MAJOR_TYPE = self::MAJOR_TYPE_TEXT_STRING;
13
14 private ?string $length = null;
15
16 private string $data;
17
18 public function __construct(string $data)
19 {
20 [$additionalInformation, $length] = LengthCalculator::getLengthOfString($data);
21
22 parent::__construct(self::MAJOR_TYPE, $additionalInformation);
23 $this->data = $data;
24 $this->length = $length;
25 }
26
27 public function __toString(): string
28 {
29 $result = parent::__toString();
30 $result .= $this->length ?? '';
31
32 return $result . $this->data;
33 }
34
35 public static function create(string $data): self
36 {
37 return new self($data);
38 }
39
40 public function getValue(): string
41 {
42 return $this->data;
43 }
44
45 public function getLength(): int
46 {
47 return mb_strlen($this->data, 'utf8');
48 }
49
50 public function normalize(): string
51 {
52 return $this->data;
53 }
54 }