AbstractProviderFactory.php
2 months ago
Dsn.php
2 months ago
FilteringProvider.php
2 months ago
NullProvider.php
2 months ago
NullProviderFactory.php
2 months ago
ProviderFactoryInterface.php
2 months ago
ProviderInterface.php
2 months ago
TranslationProviderCollection.php
2 months ago
TranslationProviderCollectionFactory.php
2 months ago
Dsn.php
93 lines
| 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 | namespace ProfilePressVendor\Symfony\Component\Translation\Provider; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\Translation\Exception\InvalidArgumentException; |
| 14 | use ProfilePressVendor\Symfony\Component\Translation\Exception\MissingRequiredOptionException; |
| 15 | /** |
| 16 | * @author Fabien Potencier <fabien@symfony.com> |
| 17 | * @author Oskar Stark <oskarstark@googlemail.com> |
| 18 | */ |
| 19 | final class Dsn |
| 20 | { |
| 21 | private $scheme; |
| 22 | private $host; |
| 23 | private $user; |
| 24 | private $password; |
| 25 | private $port; |
| 26 | private $path; |
| 27 | private $options; |
| 28 | private $originalDsn; |
| 29 | public function __construct(string $dsn) |
| 30 | { |
| 31 | $this->originalDsn = $dsn; |
| 32 | if (\false === $params = parse_url($dsn)) { |
| 33 | throw new InvalidArgumentException('The translation provider DSN is invalid.'); |
| 34 | } |
| 35 | if (!isset($params['scheme'])) { |
| 36 | throw new InvalidArgumentException('The translation provider DSN must contain a scheme.'); |
| 37 | } |
| 38 | $this->scheme = $params['scheme']; |
| 39 | if (!isset($params['host'])) { |
| 40 | throw new InvalidArgumentException('The translation provider DSN must contain a host (use "default" by default).'); |
| 41 | } |
| 42 | $this->host = $params['host']; |
| 43 | $this->user = '' !== ($params['user'] ?? '') ? rawurldecode($params['user']) : null; |
| 44 | $this->password = '' !== ($params['pass'] ?? '') ? rawurldecode($params['pass']) : null; |
| 45 | $this->port = $params['port'] ?? null; |
| 46 | $this->path = $params['path'] ?? null; |
| 47 | parse_str($params['query'] ?? '', $this->options); |
| 48 | } |
| 49 | public function getScheme(): string |
| 50 | { |
| 51 | return $this->scheme; |
| 52 | } |
| 53 | public function getHost(): string |
| 54 | { |
| 55 | return $this->host; |
| 56 | } |
| 57 | public function getUser(): ?string |
| 58 | { |
| 59 | return $this->user; |
| 60 | } |
| 61 | public function getPassword(): ?string |
| 62 | { |
| 63 | return $this->password; |
| 64 | } |
| 65 | public function getPort(?int $default = null): ?int |
| 66 | { |
| 67 | return $this->port ?? $default; |
| 68 | } |
| 69 | public function getOption(string $key, $default = null) |
| 70 | { |
| 71 | return $this->options[$key] ?? $default; |
| 72 | } |
| 73 | public function getRequiredOption(string $key) |
| 74 | { |
| 75 | if (!\array_key_exists($key, $this->options) || '' === trim($this->options[$key])) { |
| 76 | throw new MissingRequiredOptionException($key); |
| 77 | } |
| 78 | return $this->options[$key]; |
| 79 | } |
| 80 | public function getOptions(): array |
| 81 | { |
| 82 | return $this->options; |
| 83 | } |
| 84 | public function getPath(): ?string |
| 85 | { |
| 86 | return $this->path; |
| 87 | } |
| 88 | public function getOriginalDsn(): string |
| 89 | { |
| 90 | return $this->originalDsn; |
| 91 | } |
| 92 | } |
| 93 |