CoreFiles by mySites.guru
InfiniteListObject.php69 lines, 1,570 bytes, from Joomla_4.0.0-beta3-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta2
md5
8cf4bc65b82e826d6285872f3d3dab55
sha1
e82e657b11304de7f15edd18cabf9e842f187952
sha256
b3ec982edaf30c2763c5f2bceb6bb02a9859da73b90d2e3b0f57ac52e7ddda81
<?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;

use InvalidArgumentException;

final class InfiniteListObject extends AbstractCBORObject implements \Countable, \IteratorAggregate
{
    private const MAJOR_TYPE = 0b100;
    private const ADDITIONAL_INFORMATION = 0b00011111;

    /**
     * @var CBORObject[]
     */
    private $data = [];

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

    public function getNormalizedData(bool $ignoreTags = false): array
    {
        return array_map(function (CBORObject $item) use ($ignoreTags) {
            return $item->getNormalizedData($ignoreTags);
        }, $this->data);
    }

    public function add(CBORObject $item): void
    {
        $this->data[] = $item;
    }

    public function count(): int
    {
        return \count($this->data);
    }

    public function getIterator(): \Iterator
    {
        return new \ArrayIterator($this->data);
    }

    public function __toString(): string
    {
        $result = parent::__toString();
        foreach ($this->data as $object) {
            $result .= (string) $object;
        }
        $bin = hex2bin('FF');
        if (false === $bin) {
            throw new InvalidArgumentException('Unable to convert the data');
        }
        $result .= $bin;

        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.