Skip to content
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
6 changes: 0 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
},
"sort-packages": true
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dbschemix/core"
}
],
"scripts": {
"fix": [
"@phpcbf",
Expand Down
24 changes: 22 additions & 2 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use PDOException;
use OutOfBoundsException;
use dbschemix\core\command\Command;
use dbschemix\core\command\CommandInterface;
use dbschemix\core\connection\ConnectionInterface;
use dbschemix\core\connection\DriverInterface;
use dbschemix\core\exception\ConfigurationException;
use dbschemix\core\exception\ConnectionException;
use dbschemix\core\Config;
use dbschemix\pdo\internal\Connection;
use dbschemix\pdo\internal\FactoryTransaction;
use dbschemix\pdo\internal\Transaction;
use dbschemix\pdo\internal\TransactionMysql;

use function dbschemix\core\internal\get_package_path;

Expand Down Expand Up @@ -84,7 +88,7 @@ public function getSetupPath(): string
}

#[Override]
public function makeCommand(Config $config): Command
public function makeCommand(Config $config): CommandInterface
{
return new Command($this->makeConnection(), $config);
}
Expand All @@ -106,7 +110,7 @@ private function makeConnection(): ConnectionInterface
try {
return $this->connectionInstance = new Connection(
($this->connectionFactory)(),
$this->type,
$this->makeFactoryTransaction(),
);
} catch (PDOException $exception) {
throw new ConnectionException($this, $exception);
Expand All @@ -115,9 +119,25 @@ private function makeConnection(): ConnectionInterface

return $this->connectionInstance;
}

/**
* Composition root: picks the transaction factory for the resolved dialect.
*
* @infection-ignore-all
* @return class-string<FactoryTransaction>
*/
private function makeFactoryTransaction(): string
{
if ($this->type === Type::PDO_MYSQL) {
return TransactionMysql::class;
}

return Transaction::class;
}
}

/**
* @internal
* @return array{0: Type, 1: non-empty-lowercase-string}
* @throws ConfigurationException
*/
Expand Down
16 changes: 0 additions & 16 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

namespace dbschemix\pdo;

use dbschemix\pdo\internal\FactoryTransaction;
use dbschemix\pdo\internal\Transaction;
use dbschemix\pdo\internal\TransactionMysql;

/**
* @api
*/
Expand All @@ -31,16 +27,4 @@ public function value(): string
*/
return strtolower($db);
}

/**
* @return class-string<FactoryTransaction>
*/
public function makeFactoryTransaction(): string
{
if ($this === self::PDO_MYSQL) {
return TransactionMysql::class;
}

return Transaction::class;
}
}
9 changes: 5 additions & 4 deletions src/internal/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PDO;
use dbschemix\core\connection\ConnectionInterface;
use dbschemix\core\connection\TransactionInterface;
use dbschemix\pdo\Type;

/**
* @psalm-internal dbschemix\pdo
Expand All @@ -17,17 +16,19 @@
{
use ThrowPrepareException;

/**
* @param class-string<FactoryTransaction> $factoryTransaction
*/
public function __construct(
private PDO $connection,
private Type $driverType,
private string $factoryTransaction,
) {
}

#[Override]
public function beginTransaction(): TransactionInterface
{
$class = $this->driverType->makeFactoryTransaction();
return $class::begin($this->connection);
return ($this->factoryTransaction)::begin($this->connection);
}

#[Override]
Expand Down
4 changes: 2 additions & 2 deletions tests/workflow/StatementMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Testo\Test;
use dbschemix\core\connection\TransactionInterface;
use dbschemix\pdo\internal\Connection;
use dbschemix\pdo\Type;
use dbschemix\pdo\internal\TransactionMysql;

#[Test]
final class StatementMysqlTest
Expand All @@ -27,7 +27,7 @@ public function init(): void
'CREATE TABLE migration (name TEXT PRIMARY KEY, version INTEGER DEFAULT 0, atime TEXT)'
);

$this->transaction = (new Connection($pdo, Type::PDO_MYSQL))->beginTransaction();
$this->transaction = (new Connection($pdo, TransactionMysql::class))->beginTransaction();
}

/**
Expand Down
Loading