Skip to content

Commit

Permalink
Added connection pool
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreram committed Apr 14, 2022
1 parent 3be598c commit 92b065b
Show file tree
Hide file tree
Showing 11 changed files with 1,141 additions and 295 deletions.
282 changes: 23 additions & 259 deletions src/Connection.php

Large diffs are not rendered by default.

424 changes: 424 additions & 0 deletions src/ConnectionPool.php

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions src/ConnectionWorker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace Drift\DBAL;

/**
* Class ConnectionWorker.
*/
class ConnectionWorker
{
private Connection $connection;
private int $id;
private int $jobs;

/**
* @param Connection $connection
* @param int $id
*/
public function __construct(Connection $connection, int $id)
{
$this->connection = $connection;
$this->id = $id;
$this->jobs = 0;
}

public function startJob()
{
++$this->jobs;
}

public function stopJob()
{
--$this->jobs;
}

/**
* @return Connection
*/
public function getConnection(): Connection
{
return $this->connection;
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @return int
*/
public function getJobs(): int
{
return $this->jobs;
}
}
49 changes: 19 additions & 30 deletions src/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,13 @@
*/
class Credentials
{
/**
* @var string
*/
private $host;

/**
* @var string
*/
private $port;

/**
* @var string
*/
private $user;

/**
* @var string
*/
private $password;

/**
* @var string
*/
private $dbName;

/**
* @var array
*/
private $options;
private string $host;
private string $port;
private string $user;
private string $password;
private string $dbName;
private array $options;
private int $connections;

/**
* Credentials constructor.
Expand All @@ -59,21 +37,24 @@ class Credentials
* @param string $password
* @param string $dbName
* @param array $options
* @param int $connections
*/
public function __construct(
string $host,
string $port,
string $user,
string $password,
string $dbName,
array $options = []
array $options = [],
int $connections = 1
) {
$this->host = $host;
$this->port = $port;
$this->user = $user;
$this->password = $password;
$this->dbName = $dbName;
$this->options = $options;
$this->connections = $connections;
}

/**
Expand Down Expand Up @@ -124,6 +105,14 @@ public function getOptions(): array
return $this->options;
}

/**
* @return int
*/
public function getConnections(): int
{
return $this->connections;
}

/**
* To string.
*/
Expand Down
Loading

0 comments on commit 92b065b

Please sign in to comment.