29 lines
727 B
PHP
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;
|
|
}
|
|
}
|