Skip to content

Commit 6ceb533

Browse files
committed
Connection, ResultSet: $rowNormalizer is normalized to Closure
1 parent 7a93ae4 commit 6ceb533

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Database/Connection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class Connection
3030
private SqlPreprocessor $preprocessor;
3131
private ?PDO $pdo = null;
3232

33-
/** @var callable(array, ResultSet): array */
34-
private $rowNormalizer = [Helpers::class, 'normalizeRow'];
33+
/** @var ?\Closure(array<string, mixed>, ResultSet): array<string, mixed> */
34+
private ?\Closure $rowNormalizer;
3535
private ?string $sql = null;
3636
private int $transactionDepth = 0;
3737

@@ -44,9 +44,9 @@ public function __construct(
4444
private readonly ?string $password = null,
4545
private readonly array $options = [],
4646
) {
47-
if (!empty($options['newDateTime'])) {
48-
$this->rowNormalizer = fn($row, $resultSet) => Helpers::normalizeRow($row, $resultSet, DateTime::class);
49-
}
47+
$this->rowNormalizer = !empty($options['newDateTime'])
48+
? fn(array $row, ResultSet $resultSet): array => Helpers::normalizeRow($row, $resultSet, DateTime::class)
49+
: Helpers::normalizeRow(...);
5050
if (empty($options['lazy'])) {
5151
$this->connect();
5252
}
@@ -136,7 +136,7 @@ public function getReflection(): Reflection
136136
*/
137137
public function setRowNormalizer(?callable $normalizer): static
138138
{
139-
$this->rowNormalizer = $normalizer;
139+
$this->rowNormalizer = $normalizer ? $normalizer(...) : null;
140140
return $this;
141141
}
142142

src/Database/ResultSet.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
class ResultSet implements \Iterator, IRowContainer
2222
{
2323
private ?\PDOStatement $pdoStatement = null;
24-
25-
/** @var callable(array, ResultSet): array */
26-
private readonly mixed $normalizer;
2724
private Row|false|null $lastRow = null;
2825
private int $lastRowKey = -1;
2926

@@ -40,10 +37,10 @@ public function __construct(
4037
private readonly string $queryString,
4138
/** @var mixed[] */
4239
private readonly array $params,
43-
?callable $normalizer = null,
40+
/** @var ?\Closure(array<string, mixed>, self): array<string, mixed> */
41+
private readonly ?\Closure $normalizer = null,
4442
) {
4543
$time = microtime(true);
46-
$this->normalizer = $normalizer;
4744
$types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
4845

4946
try {

0 commit comments

Comments
 (0)