blob: 17442fde873a11aa7d7f7cdf7967839553c568fa [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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}