Skip to content

Commit fa18021

Browse files
committed
Provide default instances where possible for Driver constructor parameters.
Signed-off-by: Joey Smith <jsmith@webinertia.net> Signed-off-by: Joey Smith <jsmith@webinertia.net>
1 parent f48bf11 commit fa18021

File tree

7 files changed

+32
-106
lines changed

7 files changed

+32
-106
lines changed

src/ConfigProvider.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpDb\Adapter\Mysql;
66

7-
use Laminas\ServiceManager\Factory\InvokableFactory;
87
use PhpDb\Adapter\AdapterInterface;
98
use PhpDb\Adapter\Driver\DriverInterface;
109
use PhpDb\Adapter\Driver\Pdo\Result;
@@ -61,24 +60,28 @@ public function getDependencies(): array
6160
AdapterInterface::class => Container\AdapterFactory::class,
6261
Driver\Mysqli\Mysqli::class => Container\MysqliDriverFactory::class,
6362
Driver\Mysqli\Connection::class => Container\MysqliConnectionFactory::class,
64-
Driver\Mysqli\Result::class => Container\MysqliResultFactory::class,
6563
Driver\Mysqli\Statement::class => Container\MysqliStatementFactory::class,
6664
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
6765
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
6866
MysqlMetadata::class => Container\MetadataInterfaceFactory::class,
6967
PdoStatement::class => Container\PdoStatementFactory::class,
7068
PlatformInterface::class => Container\PlatformInterfaceFactory::class,
71-
Profiler\Profiler::class => InvokableFactory::class,
72-
Result::class => Container\PdoResultFactory::class,
73-
ResultSet\ResultSet::class => InvokableFactory::class,
7469
],
7570
'invokables' => [
7671
Container\ConnectionInterfaceFactoryFactory::class
77-
=> Container\ConnectionInterfaceFactoryFactory::class,
72+
=> Container\ConnectionInterfaceFactoryFactory::class,
7873
Container\DriverInterfaceFactoryFactory::class
79-
=> Container\DriverInterfaceFactoryFactory::class,
74+
=> Container\DriverInterfaceFactoryFactory::class,
8075
Container\PlatformInterfaceFactoryFactory::class
81-
=> Container\PlatformInterfaceFactoryFactory::class,
76+
=> Container\PlatformInterfaceFactoryFactory::class,
77+
Driver\Mysqli\Result::class
78+
=> Driver\Mysqli\Result::class,
79+
Profiler\Profiler::class
80+
=> Profiler\Profiler::class,
81+
Result::class
82+
=> Result::class,
83+
ResultSet\ResultSet::class
84+
=> ResultSet\ResultSet::class,
8285
],
8386
];
8487
}

src/Container/MysqliResultFactory.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Container/PdoResultFactory.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Driver/Mysqli/Mysqli.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ final class Mysqli implements DriverInterface, ProfilerAwareInterface
3232
];
3333

3434
public function __construct(
35-
protected readonly ConnectionInterface&Connection $connection,
36-
protected readonly StatementInterface&Statement $statementPrototype,
37-
protected readonly ResultInterface $resultPrototype,
35+
protected ConnectionInterface&Connection $connection,
36+
protected StatementInterface&Statement $statementPrototype = new Statement(),
37+
protected ResultInterface $resultPrototype = new Result(),
3838
array $options = []
3939
) {
4040
$this->checkEnvironment();

src/Driver/Pdo/Pdo.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,32 @@
77
use Override;
88
use PDOStatement;
99
use PhpDb\Adapter\Driver\Pdo\AbstractPdo;
10+
use PhpDb\Adapter\Driver\Pdo\AbstractPdoConnection;
1011
use PhpDb\Adapter\Driver\Pdo\Result;
12+
use PhpDb\Adapter\Driver\Pdo\Statement;
13+
use PhpDb\Adapter\Driver\PdoDriverAwareInterface;
1114
use PhpDb\Adapter\Driver\ResultInterface;
15+
use PhpDb\Adapter\Driver\StatementInterface;
1216
use PhpDb\Adapter\Mysql\DatabasePlatformNameTrait;
1317

1418
class Pdo extends AbstractPdo
1519
{
1620
use DatabasePlatformNameTrait;
1721

22+
public function __construct(
23+
protected AbstractPdoConnection|\PDO $connection,
24+
protected StatementInterface&PdoDriverAwareInterface $statementPrototype = new Statement(),
25+
protected ResultInterface $resultPrototype = new Result(),
26+
array $features = [],
27+
) {
28+
parent::__construct(
29+
$connection,
30+
$statementPrototype,
31+
$resultPrototype,
32+
$features
33+
);
34+
}
35+
1836
/**
1937
* @param PDOStatement $resource
2038
*/

test/integration/Container/MysqliResultFactoryTest.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/integration/Container/PdoResultFactoryTest.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)