AbstractProviderFactory.php
1 year ago
Dsn.php
1 year ago
FilteringProvider.php
1 year ago
NullProvider.php
1 year ago
NullProviderFactory.php
1 year ago
ProviderFactoryInterface.php
1 year ago
ProviderInterface.php
1 year ago
TranslationProviderCollection.php
1 year ago
TranslationProviderCollectionFactory.php
1 year ago
index.php
1 year ago
Dsn.php
80 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Translation\Provider; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Translation\Exception\InvalidArgumentException; |
| 5 | use MailPoetVendor\Symfony\Component\Translation\Exception\MissingRequiredOptionException; |
| 6 | final class Dsn |
| 7 | { |
| 8 | private $scheme; |
| 9 | private $host; |
| 10 | private $user; |
| 11 | private $password; |
| 12 | private $port; |
| 13 | private $path; |
| 14 | private $options; |
| 15 | private $originalDsn; |
| 16 | public function __construct(string $dsn) |
| 17 | { |
| 18 | $this->originalDsn = $dsn; |
| 19 | if (\false === ($params = \parse_url($dsn))) { |
| 20 | throw new InvalidArgumentException('The translation provider DSN is invalid.'); |
| 21 | } |
| 22 | if (!isset($params['scheme'])) { |
| 23 | throw new InvalidArgumentException('The translation provider DSN must contain a scheme.'); |
| 24 | } |
| 25 | $this->scheme = $params['scheme']; |
| 26 | if (!isset($params['host'])) { |
| 27 | throw new InvalidArgumentException('The translation provider DSN must contain a host (use "default" by default).'); |
| 28 | } |
| 29 | $this->host = $params['host']; |
| 30 | $this->user = '' !== ($params['user'] ?? '') ? \rawurldecode($params['user']) : null; |
| 31 | $this->password = '' !== ($params['pass'] ?? '') ? \rawurldecode($params['pass']) : null; |
| 32 | $this->port = $params['port'] ?? null; |
| 33 | $this->path = $params['path'] ?? null; |
| 34 | \parse_str($params['query'] ?? '', $this->options); |
| 35 | } |
| 36 | public function getScheme() : string |
| 37 | { |
| 38 | return $this->scheme; |
| 39 | } |
| 40 | public function getHost() : string |
| 41 | { |
| 42 | return $this->host; |
| 43 | } |
| 44 | public function getUser() : ?string |
| 45 | { |
| 46 | return $this->user; |
| 47 | } |
| 48 | public function getPassword() : ?string |
| 49 | { |
| 50 | return $this->password; |
| 51 | } |
| 52 | public function getPort(?int $default = null) : ?int |
| 53 | { |
| 54 | return $this->port ?? $default; |
| 55 | } |
| 56 | public function getOption(string $key, $default = null) |
| 57 | { |
| 58 | return $this->options[$key] ?? $default; |
| 59 | } |
| 60 | public function getRequiredOption(string $key) |
| 61 | { |
| 62 | if (!\array_key_exists($key, $this->options) || '' === \trim($this->options[$key])) { |
| 63 | throw new MissingRequiredOptionException($key); |
| 64 | } |
| 65 | return $this->options[$key]; |
| 66 | } |
| 67 | public function getOptions() : array |
| 68 | { |
| 69 | return $this->options; |
| 70 | } |
| 71 | public function getPath() : ?string |
| 72 | { |
| 73 | return $this->path; |
| 74 | } |
| 75 | public function getOriginalDsn() : string |
| 76 | { |
| 77 | return $this->originalDsn; |
| 78 | } |
| 79 | } |
| 80 |