CoreFiles by mySites.guru
Manager.php61 lines, 1,221 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
07116c4fcb9a0850a667063f23911a27
sha1
641b3326d925ab1a0e5581f9cbfc1df04d4a442e
sha256
4b1f7c67cb9a3aa3b31b7db35caadcfcb88c6df848b333c5d0fdb1bb0a4e05bc
<?php

declare(strict_types=1);

namespace Cose\Algorithm;

use function array_key_exists;
use InvalidArgumentException;

final class Manager
{
    /**
     * @var array<int, Algorithm>
     */
    private array $algorithms = [];

    public static function create(): self
    {
        return new self();
    }

    public function add(Algorithm ...$algorithms): self
    {
        foreach ($algorithms as $algorithm) {
            $identifier = $algorithm::identifier();
            $this->algorithms[$identifier] = $algorithm;
        }

        return $this;
    }

    /**
     * @return iterable<int>
     */
    public function list(): iterable
    {
        yield from array_keys($this->algorithms);
    }

    /**
     * @return iterable<int, Algorithm>
     */
    public function all(): iterable
    {
        yield from $this->algorithms;
    }

    public function has(int $identifier): bool
    {
        return array_key_exists($identifier, $this->algorithms);
    }

    public function get(int $identifier): Algorithm
    {
        if (! $this->has($identifier)) {
            throw new InvalidArgumentException('Unsupported algorithm');
        }

        return $this->algorithms[$identifier];
    }
}

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