CoreFiles by mySites.guru
ByteStringObject.php56 lines, 1,128 bytes, from Joomla_6.2.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 6.2.0-alpha1
md5
637826db2df53e5390db9ac840058b27
sha1
8e7dd6c6143330b938288c8bba82372417e9a552
sha256
4c180cf86b531b94f029e26a7853243851ea92872b6feecff9db30e1d15364e7
<?php

declare(strict_types=1);

namespace CBOR;

use function strlen;

/**
 * @see \CBOR\Test\ByteStringObjectTest
 */
final class ByteStringObject extends AbstractCBORObject implements Normalizable
{
    private const MAJOR_TYPE = self::MAJOR_TYPE_BYTE_STRING;

    private string $value;

    private ?string $length;

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

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

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

        return $result . $this->value;
    }

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

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

    public function getLength(): int
    {
        return strlen($this->value);
    }

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

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.