CoreFiles by mySites.guru
Manager.php61 lines, 1,221 bytes, from Joomla_5.4.10-rc1-Release_Candidate-Full_Package.zip
Raw History Compare with 5.4.9-rc1
md5
121b45786fc94c327c754321e2330cc4
sha1
4daaac53e92a6ebc1508d9da858c5155acc16f68
sha256
bfae10306122c981cd35631ff39cbcccca9c6a24cc042cf99aadcde5ecb76669
<?php

declare(strict_types=1);

namespace Cose\Algorithm;

use InvalidArgumentException;
use function array_key_exists;

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 143 releases, Joomla 5.0.0-alpha4 to 6.2.0-alpha1. See them all, or every version of this file.