| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Exception; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\Bridge; |
| 15 |
use Symfony\Component\Translation\Provider\Dsn; |
| 16 |
|
| 17 |
class UnsupportedSchemeException extends LogicException |
| 18 |
{ |
| 19 |
private const SCHEME_TO_PACKAGE_MAP = [ |
| 20 |
'crowdin' => [ |
| 21 |
'class' => Bridge\Crowdin\CrowdinProviderFactory::class, |
| 22 |
'package' => 'symfony/crowdin-translation-provider', |
| 23 |
], |
| 24 |
'loco' => [ |
| 25 |
'class' => Bridge\Loco\LocoProviderFactory::class, |
| 26 |
'package' => 'symfony/loco-translation-provider', |
| 27 |
], |
| 28 |
'lokalise' => [ |
| 29 |
'class' => Bridge\Lokalise\LokaliseProviderFactory::class, |
| 30 |
'package' => 'symfony/lokalise-translation-provider', |
| 31 |
], |
| 32 |
'phrase' => [ |
| 33 |
'class' => Bridge\Phrase\PhraseProviderFactory::class, |
| 34 |
'package' => 'symfony/phrase-translation-provider', |
| 35 |
], |
| 36 |
]; |
| 37 |
|
| 38 |
public function __construct(Dsn $dsn, ?string $name = null, array $supported = []) |
| 39 |
{ |
| 40 |
$provider = $dsn->getScheme(); |
| 41 |
if (false !== $pos = strpos($provider, '+')) { |
| 42 |
$provider = substr($provider, 0, $pos); |
| 43 |
} |
| 44 |
$package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null; |
| 45 |
if ($package && !class_exists($package['class'])) { |
| 46 |
parent::__construct(\sprintf('Unable to synchronize translations via "%s" as the provider is not installed. Try running "composer require %s".', $provider, $package['package'])); |
| 47 |
|
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
$message = \sprintf('The "%s" scheme is not supported', $dsn->getScheme()); |
| 52 |
if ($name && $supported) { |
| 53 |
$message .= \sprintf('; supported schemes for translation provider "%s" are: "%s"', $name, implode('", "', $supported)); |
| 54 |
} |
| 55 |
|
| 56 |
parent::__construct($message.'.'); |
| 57 |
} |
| 58 |
} |