Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added connection pool #24

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 23 additions & 259 deletions src/Connection.php

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

namespace Drift\DBAL;

interface ConnectionPoolInterface
{
/**
* Get the Pool's connection workers
*
* @return ConnectionWorker[]
*/
public function getWorkers(): array;
}
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