1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\Translation\Provider; 13 14use Symfony\Component\Translation\Exception\IncompleteDsnException; 15 16abstract class AbstractProviderFactory implements ProviderFactoryInterface 17{ 18 public function supports(Dsn $dsn): bool 19 { 20 return \in_array($dsn->getScheme(), $this->getSupportedSchemes(), true); 21 } 22 23 /** 24 * @return string[] 25 */ 26 abstract protected function getSupportedSchemes(): array; 27 28 protected function getUser(Dsn $dsn): string 29 { 30 if (null === $user = $dsn->getUser()) { 31 throw new IncompleteDsnException('User is not set.', $dsn->getOriginalDsn()); 32 } 33 34 return $user; 35 } 36 37 protected function getPassword(Dsn $dsn): string 38 { 39 if (null === $password = $dsn->getPassword()) { 40 throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn()); 41 } 42 43 return $password; 44 } 45} 46