CoreFiles by mySites.guru
TextStringObject.php64 lines, 1,270 bytes, from Joomla_4.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 3.9.0-beta4
md5
3f9ff94557812df39603290888d98694
sha1
e0996d0f9ca19007a871472383171133f18bd50d
sha256
3e7f95a3f3611d2f18250b941108106d0808d9e957c3418bdc3a461bbb22f9d8
<?php

declare(strict_types=1);

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2018 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace CBOR;

final class TextStringObject extends AbstractCBORObject
{
    private const MAJOR_TYPE = 0b011;

    /**
     * @var int|null
     */
    private $length;

    /**
     * @var string
     */
    private $data;

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

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

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

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

    public function getNormalizedData(bool $ignoreTags = false): string
    {
        return $this->data;
    }

    public function __toString(): string
    {
        $result = parent::__toString();
        if (null !== $this->length) {
            $result .= $this->length;
        }
        $result .= $this->data;

        return $result;
    }
}

The same content is in 3 releases, Joomla 4.0.0-beta to 4.0.0-beta3. See them all, or every version of this file.