<?php
 declare(strict_types=1); namespace Jose\Component\Core; use InvalidArgumentException; use function array_key_exists; use function sprintf; final class AlgorithmManager { private array $algorithms = []; public function __construct(iterable $algorithms) { foreach ($algorithms as $algorithm) { $this->add($algorithm); } } public function has(string $algorithm): bool { return array_key_exists($algorithm, $this->algorithms); } public function all(): array { return $this->algorithms; } public function list(): array { return array_keys($this->algorithms); } public function get(string $algorithm): Algorithm { if (! $this->has($algorithm)) { throw new InvalidArgumentException(sprintf('The algorithm "%s" is not supported.', $algorithm)); } return $this->algorithms[$algorithm]; } public function add(Algorithm $algorithm): void { $name = $algorithm->name(); $this->algorithms[$name] = $algorithm; } } 