CoreFiles by mySites.guru
ManagerFactory.php57 lines, 1,181 bytes, from Joomla_5.0.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 4.4.0-alpha4
md5
01e6e48c53f2e7c6041bac5a138d6812
sha1
849bb19839f6e0877fbdf49a4a64f624bea14cb9
sha256
86bf8b152cbba4810d9bd0c41be8e0d82af68b116aeca25f0630669368481e8d
<?php

declare(strict_types=1);

namespace Cose\Algorithm;

use function array_key_exists;
use InvalidArgumentException;

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

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

    public function add(string $alias, Algorithm $algorithm): self
    {
        $this->algorithms[$alias] = $algorithm;

        return $this;
    }

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

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

    public function generate(string ...$aliases): Manager
    {
        $manager = Manager::create();
        foreach ($aliases as $alias) {
            if (! array_key_exists($alias, $this->algorithms)) {
                throw new InvalidArgumentException(sprintf('The algorithm with alias "%s" is not supported', $alias));
            }
            $manager->add($this->algorithms[$alias]);
        }

        return $manager;
    }
}

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