data = $data; $this->length = $length; } public function add(CBORObject $object): void { $this->data[] = $object; list($this->additionalInformation, $this->length) = LengthCalculator::getLengthOfArray($this->data); } public function get(int $index): CBORObject { if (!\array_key_exists($index, $this->data)) { throw new InvalidArgumentException('Index not found.'); } return $this->data[$index]; } public function getNormalizedData(bool $ignoreTags = false): array { return array_map(function (CBORObject $item) use ($ignoreTags) { return $item->getNormalizedData($ignoreTags); }, $this->data); } public function count(): int { return \count($this->data); } public function getIterator(): \Iterator { return new \ArrayIterator($this->data); } public function __toString(): string { $result = parent::__toString(); if (null !== $this->length) { $result .= $this->length; } foreach ($this->data as $object) { $result .= (string) $object; } return $result; } }