Files
esun3d/app/code/Esun/MultiLocaleTranslation/Model/ProviderPool.php
T
2026-09-15 10:35:56 +08:00

29 lines
727 B
PHP

<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Model;
use Esun\MultiLocaleTranslation\Api\TranslationProviderInterface;
use Magento\Framework\Exception\LocalizedException;
class ProviderPool
{
/**
* @param array<string, TranslationProviderInterface> $providers
*/
public function __construct(private readonly array $providers = [])
{
}
public function get(string $code): TranslationProviderInterface
{
$provider = $this->providers[$code] ?? null;
if (!$provider instanceof TranslationProviderInterface) {
throw new LocalizedException(__('Translation provider "%1" is not available.', $code));
}
return $provider;
}
}