Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
151 lines
3.7 KiB
PHP
151 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CBOR;
|
|
|
|
use ArrayAccess;
|
|
use ArrayIterator;
|
|
use function count;
|
|
use Countable;
|
|
use InvalidArgumentException;
|
|
use Iterator;
|
|
use IteratorAggregate;
|
|
|
|
/**
|
|
* @phpstan-implements ArrayAccess<int, CBORObject>
|
|
* @phpstan-implements IteratorAggregate<int, MapItem>
|
|
* @final
|
|
*/
|
|
class IndefiniteLengthMapObject extends AbstractCBORObject implements Countable, IteratorAggregate, Normalizable, ArrayAccess
|
|
{
|
|
use MapKeyRegistryTrait;
|
|
|
|
private const MAJOR_TYPE = self::MAJOR_TYPE_MAP;
|
|
|
|
private const ADDITIONAL_INFORMATION = self::LENGTH_INDEFINITE;
|
|
|
|
/**
|
|
* @var MapItem[]
|
|
*/
|
|
private array $data = [];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct(self::MAJOR_TYPE, self::ADDITIONAL_INFORMATION);
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
$result = parent::__toString();
|
|
foreach ($this->data as $object) {
|
|
$result .= (string) $object->getKey();
|
|
$result .= (string) $object->getValue();
|
|
}
|
|
|
|
return $result . "\xFF";
|
|
}
|
|
|
|
public static function create(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public function add(CBORObject $key, CBORObject $value): self
|
|
{
|
|
$this->data[$this->registerKey($key, false)] = MapItem::create($key, $value);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Whether an entry is reachable at that offset: a key that is opaque, or that shares its offset with a key of
|
|
* another major type, is only reached by iterating the map.
|
|
*/
|
|
public function has(int|string $key): bool
|
|
{
|
|
return $this->isAddressable($this->data, $key);
|
|
}
|
|
|
|
public function remove(int|string $index): self
|
|
{
|
|
if (! $this->has($index)) {
|
|
return $this;
|
|
}
|
|
unset($this->data[$index]);
|
|
$this->unregisterKey($index);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function get(int|string $index): CBORObject
|
|
{
|
|
if (! $this->has($index)) {
|
|
throw new InvalidArgumentException('Index not found.');
|
|
}
|
|
|
|
return $this->data[$index]->getValue();
|
|
}
|
|
|
|
public function set(MapItem $object): self
|
|
{
|
|
$this->data[$this->registerKey($object->getKey(), true)] = $object;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return count($this->data);
|
|
}
|
|
|
|
/**
|
|
* @return Iterator<int, MapItem>
|
|
*/
|
|
public function getIterator(): Iterator
|
|
{
|
|
return new ArrayIterator($this->data);
|
|
}
|
|
|
|
/**
|
|
* Items that do not implement Normalizable -- the encoding tags or the "break" simple value, for instance -- have
|
|
* no native counterpart and are returned as the CBORObject they are.
|
|
*
|
|
* A key has to become a PHP array offset, which only an integer or a string can. A map holding any other kind of
|
|
* key -- a float, a boolean, null, a list, a map -- or two keys of different major types that resolve to the
|
|
* same offset, decodes and iterates, but cannot be normalized.
|
|
*
|
|
* @return array<int|string, mixed>
|
|
*/
|
|
public function normalize(): array
|
|
{
|
|
return $this->normalizeEntries($this->data);
|
|
}
|
|
|
|
public function offsetExists($offset): bool
|
|
{
|
|
return $this->has($offset);
|
|
}
|
|
|
|
public function offsetGet($offset): CBORObject
|
|
{
|
|
return $this->get($offset);
|
|
}
|
|
|
|
public function offsetSet($offset, $value): void
|
|
{
|
|
if (! $offset instanceof CBORObject) {
|
|
throw new InvalidArgumentException('Invalid key');
|
|
}
|
|
if (! $value instanceof CBORObject) {
|
|
throw new InvalidArgumentException('Invalid value');
|
|
}
|
|
|
|
$this->set(MapItem::create($offset, $value));
|
|
}
|
|
|
|
public function offsetUnset($offset): void
|
|
{
|
|
$this->remove($offset);
|
|
}
|
|
}
|