CoreFiles by mySites.guru
ManagerFactory.php58 lines, 1,203 bytes, from Joomla_5.4.11-Stable-Full_Package.zip
Raw History Compare with 5.4.10
md5
43b6bdf4302c8a9dfda2e9c1e04d1bca
sha1
7b7f9a0c973ab2ab023afe8b4edc4dab2fc43125
sha256
bf46160744b0372bf97b532123f246b8d88a9a82df01dadf09b3f876b061565e
<?php

declare(strict_types=1);

namespace Cose\Algorithm;

use InvalidArgumentException;
use function array_key_exists;
use function sprintf;

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