CoreFiles by mySites.guru
StringMetadataService.php59 lines, 1,507 bytes, from Joomla_5.0.0-beta2-Beta-Full_Package.zip
Raw History Compare with 5.0.0-beta1
md5
56244ac60338cff6445405a3be22c99d
sha1
fec21f022bb0d0110cba295a014b1ae4d3b6d709
sha256
ec55c7ef2938b261bfa1fd817fe0695f9d7ff51e5bc020b238029673096a71cd
<?php

declare(strict_types=1);

namespace Webauthn\MetadataService\Service;

use function array_key_exists;
use Webauthn\MetadataService\Exception\MissingMetadataStatementException;
use Webauthn\MetadataService\Statement\MetadataStatement;

final class StringMetadataService implements MetadataService
{
    /**
     * @var MetadataStatement[]
     */
    private array $statements = [];

    public function __construct(string ...$statements)
    {
        foreach ($statements as $statement) {
            $this->addStatements(MetadataStatement::createFromString($statement));
        }
    }

    public static function create(string ...$statements): self
    {
        return new self(...$statements);
    }

    public function addStatements(MetadataStatement ...$statements): self
    {
        foreach ($statements as $statement) {
            $aaguid = $statement->getAaguid();
            if ($aaguid === null) {
                continue;
            }
            $this->statements[$aaguid] = $statement;
        }

        return $this;
    }

    public function list(): iterable
    {
        yield from array_keys($this->statements);
    }

    public function has(string $aaguid): bool
    {
        return array_key_exists($aaguid, $this->statements);
    }

    public function get(string $aaguid): MetadataStatement
    {
        array_key_exists($aaguid, $this->statements) || throw MissingMetadataStatementException::create($aaguid);

        return $this->statements[$aaguid];
    }
}

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