Skip to content

Commit 73ed15d

Browse files
committed
Added readme (#15)
1 parent 2e61e0b commit 73ed15d

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ OpenSwoole is a programmatic platform building modernized systems with async IO,
1010
+ __Discord__: <https://discord.gg/5QC57RNPpw>
1111
+ __IDE Helper__: <https://github.com/openswoole/ide-helper>
1212

13+
## Install
14+
15+
You can add this package to your project using [Composer](https://getcomposer.org):
16+
17+
```bash
18+
composer require openswoole/core
19+
```
20+
1321
## Documentation
1422

1523
Documentation for Open Swoole can be found on the [Open Swoole website](https://openswoole.com/docs).
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of OpenSwoole.
6+
* @link https://openswoole.com
7+
* @contact [email protected]
8+
*/
9+
namespace OpenSwoole\Core\Coroutine\Client;
10+
11+
use OpenSwoole\Client\Exception;
12+
use OpenSwoole\Coroutine\PostgreSQL;
13+
14+
final class PostgresClientFactory implements ClientFactoryInterface
15+
{
16+
/**
17+
* @param mixed $config
18+
* @throws Exception
19+
*/
20+
public static function make($config)
21+
{
22+
if ($config instanceof PostgresConfig) {
23+
$postgres = new PostgreSQL();
24+
$postgres->connect($config->getConnectionString());
25+
return $postgres;
26+
}
27+
28+
throw new Exception('Wrong config used');
29+
}
30+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of OpenSwoole.
6+
* @link https://openswoole.com
7+
* @contact [email protected]
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

Comments
 (0)