|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * This file is part of OpenSwoole. |
| 6 | + * @link https://openswoole.com |
| 7 | + |
| 8 | + */ |
| 9 | +namespace OpenSwoole\Core\Coroutine\Client; |
| 10 | + |
| 11 | +class PostgresConfig implements ClientConfigInterface |
| 12 | +{ |
| 13 | + /** @var string */ |
| 14 | + protected $host = '127.0.0.1'; |
| 15 | + |
| 16 | + /** @var int */ |
| 17 | + protected $port = 5432; |
| 18 | + |
| 19 | + /** @var string */ |
| 20 | + protected $dbname = 'test'; |
| 21 | + |
| 22 | + /** @var string */ |
| 23 | + protected $username = 'postgres'; |
| 24 | + |
| 25 | + /** @var string */ |
| 26 | + protected $password = ''; |
| 27 | + |
| 28 | + public function getHost(): string |
| 29 | + { |
| 30 | + return $this->host; |
| 31 | + } |
| 32 | + |
| 33 | + public function withHost($host): self |
| 34 | + { |
| 35 | + $this->host = $host; |
| 36 | + return $this; |
| 37 | + } |
| 38 | + |
| 39 | + public function getPort(): int |
| 40 | + { |
| 41 | + return $this->port; |
| 42 | + } |
| 43 | + |
| 44 | + public function withPort(int $port): self |
| 45 | + { |
| 46 | + $this->port = $port; |
| 47 | + return $this; |
| 48 | + } |
| 49 | + |
| 50 | + public function getDbname(): string |
| 51 | + { |
| 52 | + return $this->dbname; |
| 53 | + } |
| 54 | + |
| 55 | + public function withDbname(string $dbname): self |
| 56 | + { |
| 57 | + $this->dbname = $dbname; |
| 58 | + return $this; |
| 59 | + } |
| 60 | + |
| 61 | + public function getUsername(): string |
| 62 | + { |
| 63 | + return $this->username; |
| 64 | + } |
| 65 | + |
| 66 | + public function withUsername(string $username): self |
| 67 | + { |
| 68 | + $this->username = $username; |
| 69 | + return $this; |
| 70 | + } |
| 71 | + |
| 72 | + public function getPassword(): string |
| 73 | + { |
| 74 | + return $this->password; |
| 75 | + } |
| 76 | + |
| 77 | + public function withPassword(string $password): self |
| 78 | + { |
| 79 | + $this->password = $password; |
| 80 | + return $this; |
| 81 | + } |
| 82 | + |
| 83 | + public function getConnectionString(): string |
| 84 | + { |
| 85 | + return 'host=' . $this->host . |
| 86 | + ';port=' . $this->port . |
| 87 | + ';dbname=' . $this->dbname . |
| 88 | + ';user=' . $this->username . |
| 89 | + ';password=' . $this->password; |
| 90 | + } |
| 91 | +} |
0 commit comments