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
16 changes: 8 additions & 8 deletions composer.lock

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

6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ parameters:
count: 1
path: src/Driver.php

-
message: '#^Method PhpDb\\Mysql\\Driver\:\:getResultPrototype\(\) should return PhpDb\\Mysql\\Result but returns PhpDb\\Adapter\\Driver\\ResultInterface\.$#'
identifier: return.type
count: 1
path: src/Driver.php

-
message: '#^Parameter \#1 \$resource \(mysqli\|mysqli_stmt\|PhpDb\\Mysql\\mysqli_result\) of method PhpDb\\Mysql\\Driver\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#'
identifier: method.childParameterType
Expand Down
30 changes: 0 additions & 30 deletions src/DatabasePlatformNameTrait.php

This file was deleted.

7 changes: 3 additions & 4 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

final class Driver implements DriverInterface, ProfilerAwareInterface
{
use DatabasePlatformNameTrait;

protected ?ProfilerInterface $profiler = null;

/** @var array */
Expand All @@ -33,8 +31,8 @@ final class Driver implements DriverInterface, ProfilerAwareInterface

public function __construct(
protected readonly ConnectionInterface&Connection $connection,
protected readonly StatementInterface&Statement $statementPrototype,
protected readonly ResultInterface $resultPrototype,
protected readonly StatementInterface&Statement $statementPrototype = new Statement(),
protected readonly ResultInterface&Result $resultPrototype = new Result(),
array $options = []
) {
$this->checkEnvironment();
Expand All @@ -44,6 +42,7 @@ public function __construct(
if ($this->connection instanceof DriverAwareInterface) {
$this->connection->setDriver($this);
}

if ($this->statementPrototype instanceof DriverAwareInterface) {
$this->statementPrototype->setDriver($this);
}
Expand Down
16 changes: 16 additions & 0 deletions src/Pdo/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@

use function array_diff_key;
use function implode;
use function is_array;
use function is_int;
use function is_string;
use function strtolower;

class Connection extends AbstractPdoConnection
{
/**
* Constructor
*
* @throws Exception\InvalidArgumentException
*/
public function __construct(
PDO|array $connectionParameters
) {
if (is_array($connectionParameters)) {
$this->setConnectionParameters($connectionParameters);
} elseif ($connectionParameters instanceof PDO) {
$this->setResource($connectionParameters);
}
}

/**
* {@inheritDoc}
*/
Expand Down
28 changes: 26 additions & 2 deletions src/Pdo/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,39 @@
namespace PhpDb\Mysql\Pdo;

use Override;
use PDO;
use PDOStatement;
use PhpDb\Adapter\Driver\Feature\DriverFeatureProviderInterface;
use PhpDb\Adapter\Driver\Pdo\AbstractPdo;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Driver\PdoDriverAwareInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Mysql\DatabasePlatformNameTrait;
use PhpDb\Adapter\Driver\StatementInterface;

class Driver extends AbstractPdo
{
use DatabasePlatformNameTrait;
public function __construct(
(PdoConnectionInterface&PdoDriverAwareInterface)|PDO $connection,
StatementInterface&PdoDriverAwareInterface $statementPrototype,
ResultInterface $resultPrototype,
array $features = [],
) {
$this->connection = $connection;
$this->statementPrototype = $statementPrototype;
$this->resultPrototype = $resultPrototype;

if (! $this->connection instanceof PDO) {
$this->connection->setDriver($this);
}

$this->statementPrototype->setDriver($this);

// $features is not constructor promoted because $this->features is defined in the trait
if ($features !== [] && $this instanceof DriverFeatureProviderInterface) {
$this->addFeatures($features);
}
}

/**
* @param PDOStatement $resource
Expand Down
6 changes: 3 additions & 3 deletions test/integration/TestFixtures/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS test (
name VARCHAR(255) NOT NULL,
value VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
) ENGINE=InnoDB;

INSERT INTO test (name, value) VALUES
('foo', 'bar'),
Expand All @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS test_charset (
field$ VARCHAR(255) NOT NULL,
field_ VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
) ENGINE=InnoDB;

INSERT INTO test_charset (field$, field_) VALUES
('foo', 'bar'),
Expand All @@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS test_audit_trail (
test_value_new VARCHAR(255) NOT NULL,
changed TIMESTAMP,
PRIMARY KEY (id)
);
) ENGINE=InnoDB;

DROP VIEW IF EXISTS test_view;
CREATE VIEW test_view
Expand Down
8 changes: 0 additions & 8 deletions test/unit/Pdo/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ protected function setUp(): void
);
}

public function testGetDatabasePlatformName(): void
{
// Test platform name for SqlServer
//$this->pdo->getConnection()->setConnectionParameters(['driver' => 'pdo_mysql']);
self::assertEquals('Mysql', $this->pdo->getDatabasePlatformName());
self::assertEquals('MySQL', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL));
}

/** @psalm-return array<array-key, array{0: int|string, 1: null|string, 2: string}> */
public static function getParamsAndType(): array
{
Expand Down