CoreFiles by mySites.guru
ManagerFactory.php50 lines, 1,062 bytes, from Joomla_4.4.13-Stable-Full_Package.zip
Raw History Compare with 4.4.12
md5
f3874436070429a89a97296e16de4a3f
sha1
18919edeffd68f74186f3a1253d13f9d82b6c882
sha256
32dc378355e48b607c0df35d125386a7de2eb86cb6caa3139a4f9f8535f87a5a
<?php

declare(strict_types=1);

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2019 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace Cose\Algorithm;

use Assert\Assertion;

class ManagerFactory
{
    /**
     * @var Algorithm[]
     */
    private $algorithms = [];

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

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

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

    public function create(array $aliases): Manager
    {
        $manager = new Manager();
        foreach ($aliases as $alias) {
            Assertion::keyExists($this->algorithms, $alias, sprintf('The algorithm with alias "%s" is not supported', $alias));
            $manager->add($this->algorithms[$alias]);
        }

        return $manager;
    }
}

The same content is in 131 releases, Joomla 4.0.0-beta to 4.4.14. See them all, or every version of this file.