AbstractProviderFactory.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.', $dsn->getScheme().'://'.$dsn->getHost());
  25. }
  26. protected function getPassword(Dsn $dsn): string
  27. {
  28. return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
  29. }
  30. }