CoreFiles by mySites.guru
TextStringObject.php54 lines, 1,118 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
6b27269506401729df10f95d0e4d2ca9
sha1
3e6c655749bb3189459886df7b03b2b0100b0f09
sha256
d6a2d7e10cae70cc4c3ae3e16298194b791d54a21fc8749296c9167541215de8
<?php

declare(strict_types=1);

namespace CBOR;

/**
 * @see \CBOR\Test\TextStringObjectTest
 */
final class TextStringObject extends AbstractCBORObject implements Normalizable
{
    private const MAJOR_TYPE = self::MAJOR_TYPE_TEXT_STRING;

    private ?string $length = null;

    private string $data;

    public function __construct(string $data)
    {
        [$additionalInformation, $length] = LengthCalculator::getLengthOfString($data);

        parent::__construct(self::MAJOR_TYPE, $additionalInformation);
        $this->data = $data;
        $this->length = $length;
    }

    public function __toString(): string
    {
        $result = parent::__toString();
        $result .= $this->length ?? '';

        return $result . $this->data;
    }

    public static function create(string $data): self
    {
        return new self($data);
    }

    public function getValue(): string
    {
        return $this->data;
    }

    public function getLength(): int
    {
        return mb_strlen($this->data, 'utf8');
    }

    public function normalize(): string
    {
        return $this->data;
    }
}

The same content is in 32 releases, Joomla 6.1.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.