Skip to content

Commit a8e7c13

Browse files
committed
Added connection pool
1 parent 3b180d2 commit a8e7c13

10 files changed

+1137
-300
lines changed

Diff for: src/Connection.php

+23-265
Large diffs are not rendered by default.

Diff for: src/ConnectionPool.php

+425
Large diffs are not rendered by default.

Diff for: src/ConnectionWorker.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the DriftPHP Project
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <[email protected]>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Drift\DBAL;
17+
18+
/**
19+
* Class ConnectionWorker.
20+
*/
21+
class ConnectionWorker
22+
{
23+
private Connection $connection;
24+
private int $id;
25+
private int $jobs;
26+
27+
/**
28+
* @param Connection $connection
29+
* @param int $id
30+
*/
31+
public function __construct(Connection $connection, int $id)
32+
{
33+
$this->connection = $connection;
34+
$this->id = $id;
35+
$this->jobs = 0;
36+
}
37+
38+
public function startJob()
39+
{
40+
++$this->jobs;
41+
}
42+
43+
public function stopJob()
44+
{
45+
--$this->jobs;
46+
}
47+
48+
/**
49+
* @return Connection
50+
*/
51+
public function getConnection(): Connection
52+
{
53+
return $this->connection;
54+
}
55+
56+
/**
57+
* @return int
58+
*/
59+
public function getId(): int
60+
{
61+
return $this->id;
62+
}
63+
64+
/**
65+
* @return int
66+
*/
67+
public function getJobs(): int
68+
{
69+
return $this->jobs;
70+
}
71+
}

Diff for: src/Credentials.php

+19-30
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,13 @@
2020
*/
2121
class Credentials
2222
{
23-
/**
24-
* @var string
25-
*/
26-
private $host;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $port;
32-
33-
/**
34-
* @var string
35-
*/
36-
private $user;
37-
38-
/**
39-
* @var string
40-
*/
41-
private $password;
42-
43-
/**
44-
* @var string
45-
*/
46-
private $dbName;
47-
48-
/**
49-
* @var array
50-
*/
51-
private $options;
23+
private string $host;
24+
private string $port;
25+
private string $user;
26+
private string $password;
27+
private string $dbName;
28+
private array $options;
29+
private int $connections;
5230

5331
/**
5432
* Credentials constructor.
@@ -59,21 +37,24 @@ class Credentials
5937
* @param string $password
6038
* @param string $dbName
6139
* @param array $options
40+
* @param int $connections
6241
*/
6342
public function __construct(
6443
string $host,
6544
string $port,
6645
string $user,
6746
string $password,
6847
string $dbName,
69-
array $options = []
48+
array $options = [],
49+
int $connections = 1
7050
) {
7151
$this->host = $host;
7252
$this->port = $port;
7353
$this->user = $user;
7454
$this->password = $password;
7555
$this->dbName = $dbName;
7656
$this->options = $options;
57+
$this->connections = $connections;
7758
}
7859

7960
/**
@@ -124,6 +105,14 @@ public function getOptions(): array
124105
return $this->options;
125106
}
126107

108+
/**
109+
* @return int
110+
*/
111+
public function getConnections(): int
112+
{
113+
return $this->connections;
114+
}
115+
127116
/**
128117
* To string.
129118
*/

0 commit comments

Comments
 (0)