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.

45 lines
1.1 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\Provider;
  11. use Symfony\Component\Translation\Exception\IncompleteDsnException;
  12. abstract class AbstractProviderFactory implements ProviderFactoryInterface
  13. {
  14. public function supports(Dsn $dsn): bool
  15. {
  16. return \in_array($dsn->getScheme(), $this->getSupportedSchemes(), true);
  17. }
  18. /**
  19. * @return string[]
  20. */
  21. abstract protected function getSupportedSchemes(): array;
  22. protected function getUser(Dsn $dsn): string
  23. {
  24. if (null === $user = $dsn->getUser()) {
  25. throw new IncompleteDsnException('User is not set.', $dsn->getOriginalDsn());
  26. }
  27. return $user;
  28. }
  29. protected function getPassword(Dsn $dsn): string
  30. {
  31. if (null === $password = $dsn->getPassword()) {
  32. throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
  33. }
  34. return $password;
  35. }
  36. }