Skip to content

Commit

Permalink
Merge branch '1-2-0' into 'main'
Browse files Browse the repository at this point in the history
1-2-1

See merge request fluxlabs/flux-eco/storage!6
  • Loading branch information
mstuder committed Apr 22, 2022
2 parents 577cd13 + e5787fa commit 7b864f8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## [1.2.1]
* removed use swoole PDOConfig OR mysql_pdo
* fix bug hostname in database config

## [1.2.0]
* use swoole PDOConfig OR mysql_pdo

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flux-eco/storage",
"description": "Handling mysql databases with json based table schemas",
"version": "1.2.0",
"version": "1.2.1",
"keywords": [
"flux-eco",
"storage",
Expand All @@ -27,7 +27,8 @@
"ext-yaml": "*",
"flux-eco/dot-env": ">=0.0.1",
"laminas/laminas-code": ">=4.4",
"laminas/laminas-db": ">=2.12"
"laminas/laminas-db": ">=2.12",
"ext-pdo": "*"
},
"require-dev": {
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 7 additions & 22 deletions src/Adapters/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,13 @@ public static function newFromEnv(string $tableName, array $jsonSchema, string $
{
$apiEnv = Env::new($envPrefix);

if(class_exists('PDOConfig')) {
$databaseConfig = (new PDOConfig())
->withHost( $apiEnv->getHost())
->withPort(3306)
// ->withUnixSocket('/tmp/mysql.sock')
->withDbName($apiEnv->getName())
->withCharset('utf8mb4')
->withUsername($apiEnv->getUser())
->withPassword($apiEnv->getPassword());
} else {
$databaseConfig = Adapters\MySqlDatabase\DatabaseConfig::new(
$apiEnv->getHost(),
$apiEnv->getDriver(),
$apiEnv->getName(),
$apiEnv->getUser(),
$apiEnv->getPassword()
);
}




$databaseConfig = Adapters\MySqlDatabase\DatabaseConfig::new(
$apiEnv->getHost(),
$apiEnv->getDriver(),
$apiEnv->getName(),
$apiEnv->getUser(),
$apiEnv->getPassword()
);


$databaseClient = Adapters\MySqlDatabase\MysqlDatabaseClient::new(
Expand Down
19 changes: 7 additions & 12 deletions src/Adapters/MySqlDatabase/DatabaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,43 @@

class DatabaseConfig implements Ports\Database\DatabaseConfig
{
private string $host;
private string $hostname;
private string $driver;
private string $database;
private string $password;
private string $username;

private function __construct(
string $host,
string $hostname,
string $driver,
string $database,
string $username,
string $password
) {
$this->host = $host;
$this->hostname = $hostname;
$this->driver = $driver;
$this->database = $database;
$this->username = $username;
$this->password = $password;
}

public static function new(
string $host,
string $hostname,
string $driver,
string $database,
string $username,
string $password,
) : self
{
return new self(
$host,
$hostname,
$driver,
$database,
$username,
$password
);
}

final public function getDbName() : string
{
return $this->database;
}

final public function getDatabase() : string
{
return $this->database;
Expand All @@ -60,9 +55,9 @@ final public function getDriver() : string
return $this->driver;
}

final public function getHost() : string
final public function getHostname() : string
{
return $this->host;
return $this->hostname;
}

final public function getPassword() : string
Expand Down
6 changes: 3 additions & 3 deletions src/Adapters/MySqlDatabase/MysqlDatabaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class MysqlDatabaseClient implements Ports\Database\DatabaseClient
{
protected static array $instances = [];

private DatabaseConfig|PDOConfig $databaseConfig;
private DatabaseConfig $databaseConfig;
private Adapter $dbAdapter;
private Sql $sql;
private TableGateway $tableGateway;
private array $jsonSchema;

private function __construct(DatabaseConfig|PDOConfig $databaseConfig, Adapter $dbAdapter, Sql $sql, TableGateway $tableGateway, array $jsonSchema)
private function __construct(DatabaseConfig $databaseConfig, Adapter $dbAdapter, Sql $sql, TableGateway $tableGateway, array $jsonSchema)
{
$this->databaseConfig = $databaseConfig;
$this->dbAdapter = $dbAdapter;
Expand All @@ -37,7 +37,7 @@ private function __construct(DatabaseConfig|PDOConfig $databaseConfig, Adapter $
public static function new(
string $tableName,
array $jsonSchema,
DatabaseConfig|PDOConfig $databaseConfig
DatabaseConfig $databaseConfig
): self
{
$databaseName = $databaseConfig->getDbname();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Ports/Database/DatabaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function getDatabase() : string;

public function getDriver() : string;

public function getHost() : string;
public function getHostName() : string;

public function getPassword() : string;

Expand Down

0 comments on commit 7b864f8

Please sign in to comment.