CoreFiles by mySites.guru
IndefiniteLengthByteStringObject.php84 lines, 1,708 bytes, from Joomla_5.1.0-alpha4-Alpha-Full_Package.zip
Raw History Compare with 5.1.0-alpha3
md5
02959da4a34c6b55e3df9e44d0e8b2a2
sha1
28a03c413de7abe9e6833764b4d2e5d750528213
sha256
62b870018d9174ec0adc7def591e441f42bc2440adc1c9604fcd574df84b952c
<?php

declare(strict_types=1);

namespace CBOR;

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

    private const ADDITIONAL_INFORMATION = self::LENGTH_INDEFINITE;

    /**
     * @var ByteStringObject[]
     */
    private array $chunks = [];

    public function __construct()
    {
        parent::__construct(self::MAJOR_TYPE, self::ADDITIONAL_INFORMATION);
    }

    public function __toString(): string
    {
        $result = parent::__toString();
        foreach ($this->chunks as $chunk) {
            $result .= $chunk->__toString();
        }

        return $result . "\xFF";
    }

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

    public function add(ByteStringObject $chunk): self
    {
        $this->chunks[] = $chunk;

        return $this;
    }

    public function append(string $chunk): self
    {
        $this->add(ByteStringObject::create($chunk));

        return $this;
    }

    public function getValue(): string
    {
        $result = '';
        foreach ($this->chunks as $chunk) {
            $result .= $chunk->getValue();
        }

        return $result;
    }

    public function getLength(): int
    {
        $length = 0;
        foreach ($this->chunks as $chunk) {
            $length += $chunk->getLength();
        }

        return $length;
    }

    public function normalize(): string
    {
        $result = '';
        foreach ($this->chunks as $chunk) {
            $result .= $chunk->normalize();
        }

        return $result;
    }
}

The same content is in 41 releases, Joomla 5.0.0-alpha1 to 5.2.0-alpha3. See them all, or every version of this file.