Skip to content

Commit 878a412

Browse files
committed
Signed-off-by: Joey Smith <jsmith@webinertia.net>
1 parent d5db172 commit 878a412

13 files changed

+105
-156
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"require": {
3535
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
36-
"php-db/phpdb": "^0.3.3"
36+
"php-db/phpdb": "^0.3.4"
3737
},
3838
"require-dev": {
3939
"ext-mysqli": "*",

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ConfigProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpDb\Adapter\AdapterInterface;
88
use PhpDb\Adapter\Driver\DriverInterface;
9+
use PhpDb\Adapter\Driver\Pdo\Statement as PdoStatement;
910
use PhpDb\Adapter\Driver\PdoDriverInterface;
1011
use PhpDb\Adapter\Mysql\Driver;
1112
use PhpDb\Adapter\Mysql\Metadata\Source\MysqlMetadata;
@@ -58,13 +59,12 @@ public function getDependencies(): array
5859
AdapterInterface::class => Container\AdapterFactory::class,
5960
Driver\Mysqli\Mysqli::class => Container\MysqliDriverFactory::class,
6061
Driver\Mysqli\Connection::class => Container\MysqliConnectionFactory::class,
62+
Driver\Mysqli\Statement::class => Container\StatementInterfaceFactory::class,
6163
Driver\Pdo\Pdo::class => Container\PdoDriverFactory::class,
6264
Driver\Pdo\Connection::class => Container\PdoConnectionFactory::class,
65+
PdoStatement::class => Container\StatementInterfaceFactory::class,
6366
MysqlMetadata::class => Container\MetadataInterfaceFactory::class,
6467
PlatformInterface::class => Container\PlatformInterfaceFactory::class,
65-
// Uncomment to override the default implementations
66-
//Driver\Mysqli\Statement::class => Container\MysqliStatementFactory::class,
67-
//PdoStatement::class => Container\PdoStatementFactory::class,
6868
],
6969
'invokables' => [
7070
Container\ConnectionInterfaceFactoryFactory::class

src/Container/AdapterFactory.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpDb\Adapter\Exception\RuntimeException;
1313
use PhpDb\Adapter\Platform\PlatformInterface;
1414
use PhpDb\Adapter\Profiler\ProfilerInterface;
15+
use PhpDb\ResultSet\ResultSet;
1516
use PhpDb\ResultSet\ResultSetInterface;
1617
use Psr\Container\ContainerInterface;
1718

@@ -55,26 +56,21 @@ public function __invoke(ContainerInterface $container): AdapterInterface
5556
/** @var PlatformInterface $platformInstance */
5657
$platformInstance = $container->get(PlatformInterface::class);
5758

58-
if (! $container->has(ResultSetInterface::class)) {
59-
throw new ServiceNotFoundException(sprintf(
60-
'ResultSet "%s" is not registered in the adapter manager.',
61-
ResultSetInterface::class
62-
));
63-
}
64-
6559
/** @var ResultSetInterface $resultSetInstance */
66-
$resultSetInstance = $container->get(ResultSetInterface::class);
60+
$resultSetInstance = $container->has(ResultSetInterface::class)
61+
? $container->get(ResultSetInterface::class)
62+
: null;
6763

6864
/** @var ProfilerInterface|null $profilerInstanceOrNull */
6965
$profilerInstanceOrNull = $container->has(ProfilerInterface::class)
7066
? $container->get(ProfilerInterface::class)
7167
: null;
7268

7369
return new Adapter(
74-
$driverInstance,
75-
$platformInstance,
76-
$resultSetInstance,
77-
$profilerInstanceOrNull
70+
driver: $driverInstance,
71+
platform: $platformInstance,
72+
queryResultSetPrototype: $resultSetInstance ?? new ResultSet(),
73+
profiler: $profilerInstanceOrNull
7874
);
7975
}
8076
}

src/Container/MysqliDriverFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public function __invoke(ContainerInterface $container): Driver\DriverInterface&
2929
$statementInstance = $container->get(Mysqli\Statement::class);
3030

3131
/** @var Driver\ResultInterface&Mysqli\Result $resultInstance */
32-
$resultInstance = $container->get(Mysqli\Result::class);
32+
$resultInstance = $container->has(Mysqli\Result::class) ? $container->get(Mysqli\Result::class) : null;
3333

3434
return new Mysqli\Mysqli(
35-
$connectionInstance,
36-
$statementInstance,
37-
$resultInstance,
38-
$options
35+
connection: $connectionInstance,
36+
statementPrototype: $statementInstance,
37+
resultPrototype: $resultInstance ?? new Mysqli\Result(),
38+
options: $options
3939
);
4040
}
4141

src/Container/MysqliStatementFactory.php

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

src/Container/PdoStatementFactory.php

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpDb\Adapter\Mysql\Container;
6+
7+
use PhpDb\Adapter\Driver\Pdo\Statement as PdoStatement;
8+
use PhpDb\Adapter\Driver\StatementInterface;
9+
use PhpDb\Adapter\Mysql\Driver\Mysqli\Statement as MysqliStatement;
10+
use Psr\Container\ContainerInterface;
11+
12+
/** @internal */
13+
final class StatementInterfaceFactory
14+
{
15+
/**
16+
* @param string $requestedName
17+
* @phpstan-param class-string $requestedName
18+
*/
19+
public function __invoke(
20+
ContainerInterface $container,
21+
$requestedName
22+
): (StatementInterface&PdoStatement)|(StatementInterface&MysqliStatement) {
23+
/** @var array $config */
24+
$config = $container->get('config');
25+
26+
/** @var array $dbConfig */
27+
$dbConfig = $config['db'] ?? [];
28+
29+
/** @var array $options */
30+
$options = $dbConfig['options'] ?? [];
31+
32+
return new $requestedName(options: $options);
33+
}
34+
}

src/Driver/Mysqli/Statement.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
final class Statement implements StatementInterface, DriverAwareInterface, ProfilerAwareInterface
2424
{
25+
protected bool $bufferResults;
2526
protected \mysqli $mysqli;
2627

2728
protected Mysqli $driver;
2829

29-
protected ?ProfilerInterface $profiler;
30+
protected ?ProfilerInterface $profiler = null;
3031

3132
protected string $sql = '';
3233

@@ -36,8 +37,14 @@ final class Statement implements StatementInterface, DriverAwareInterface, Profi
3637

3738
public function __construct(
3839
protected ParameterContainer $parameterContainer = new ParameterContainer(),
39-
protected bool $bufferResults = false
40+
array|bool $options = false
4041
) {
42+
if (is_array($options)) {
43+
$this->bufferResults = $options['buffer_results'] ?? false;
44+
} else {
45+
// Provide backward compatibility for boolean parameter
46+
$this->bufferResults = $options;
47+
}
4148
}
4249

4350
#[Override]

src/Sql/Platform/Mysql/SelectDecorator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpDb\Sql\Platform\PlatformDecoratorInterface;
1111
use PhpDb\Sql\Select;
1212

13-
1413
/** @internal */
1514
final class SelectDecorator extends Select implements PlatformDecoratorInterface
1615
{

0 commit comments

Comments
 (0)