AbstractProviderFactory.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. }