You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

3 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Exception;
  11. use Symfony\Component\Translation\Bridge;
  12. use Symfony\Component\Translation\Provider\Dsn;
  13. class UnsupportedSchemeException extends LogicException
  14. {
  15. private const SCHEME_TO_PACKAGE_MAP = [
  16. 'crowdin' => [
  17. 'class' => Bridge\Crowdin\CrowdinProviderFactory::class,
  18. 'package' => 'symfony/crowdin-translation-provider',
  19. ],
  20. 'loco' => [
  21. 'class' => Bridge\Loco\LocoProviderFactory::class,
  22. 'package' => 'symfony/loco-translation-provider',
  23. ],
  24. 'lokalise' => [
  25. 'class' => Bridge\Lokalise\LokaliseProviderFactory::class,
  26. 'package' => 'symfony/lokalise-translation-provider',
  27. ],
  28. ];
  29. public function __construct(Dsn $dsn, string $name = null, array $supported = [])
  30. {
  31. $provider = $dsn->getScheme();
  32. if (false !== $pos = strpos($provider, '+')) {
  33. $provider = substr($provider, 0, $pos);
  34. }
  35. $package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null;
  36. if ($package && !class_exists($package['class'])) {
  37. parent::__construct(sprintf('Unable to synchronize translations via "%s" as the provider is not installed; try running "composer require %s".', $provider, $package['package']));
  38. return;
  39. }
  40. $message = sprintf('The "%s" scheme is not supported', $dsn->getScheme());
  41. if ($name && $supported) {
  42. $message .= sprintf('; supported schemes for translation provider "%s" are: "%s"', $name, implode('", "', $supported));
  43. }
  44. parent::__construct($message.'.');
  45. }
  46. }