Skip to content

Commit 0857cdb

Browse files
committed
use PHP 8
1 parent 9a993b1 commit 0857cdb

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.4",
18-
"illuminate/contracts": "^6.20.14|^7.30.4|^8.40|^9.0",
19-
"illuminate/support": "^6.20.14|^7.30.4|^8.40|^9.0",
20-
"illuminate/database": "^6.20.14|^7.30.4|^8.40|^9.0",
17+
"php": "^8.0",
18+
"ext-pdo": "*",
19+
"illuminate/contracts": "^9.0",
20+
"illuminate/support": "^9.0",
21+
"illuminate/database": "^9.0",
2122
"psr/log": "^1|^2|^3"
2223
},
2324
"autoload": {

src/QueryLogger/QueryLogger.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414

1515
namespace RodrigoPedra\QueryLogger;
1616

17+
use Illuminate\Contracts\Config\Repository;
1718
use Illuminate\Database\Events\QueryExecuted;
1819
use Psr\Log\LoggerInterface;
1920

2021
class QueryLogger
2122
{
2223
protected LoggerInterface $logger;
24+
protected Repository $config;
2325

24-
public function __construct(LoggerInterface $logger)
26+
public function __construct(LoggerInterface $logger, Repository $config)
2527
{
2628
$this->logger = $logger;
29+
$this->config = $config;
2730
}
2831

2932
public function handle(QueryExecuted $event)
@@ -41,6 +44,7 @@ public function handle(QueryExecuted $event)
4144
'bindings' => $event->bindings,
4245
'time' => $event->time,
4346
'connection' => $event->connectionName,
47+
'database' => $this->config->get("database.connections.{$event->connectionName}.database"),
4448
]);
4549
}
4650

@@ -57,7 +61,7 @@ protected function prepareQuery(string $query, array $bindings): string
5761
return $query;
5862
}
5963

60-
protected function prepareValue($pdo, $value): string
64+
protected function prepareValue(?\PDO $pdo, $value): string
6165
{
6266
if (\is_null($value)) {
6367
return 'NULL';
@@ -75,23 +79,23 @@ protected function prepareValue($pdo, $value): string
7579
return $this->quote($pdo, '[BINARY DATA]');
7680
}
7781

78-
if (\is_object($value) && \method_exists($value, '__toString')) {
79-
$value = \strval($value);
80-
}
81-
8282
if (\is_object($value) && \method_exists($value, 'toString')) {
8383
$value = $value->toString();
8484
}
8585

86-
if (\is_object($value) && \is_a($value, \DateTimeInterface::class)) {
86+
if ($value instanceof \DateTimeInterface) {
8787
$value = $value->format('Y-m-d H:i:s');
8888
}
8989

90+
if ($value instanceof \Stringable) {
91+
$value = \strval($value);
92+
}
93+
9094
// objects not implementing __toString() or toString() will fail here
9195
return $this->quote($pdo, \strval($value));
9296
}
9397

94-
protected function quote($pdo, string $value): string
98+
protected function quote(?\PDO $pdo, string $value): string
9599
{
96100
if ($pdo) {
97101
return $pdo->quote($value);

0 commit comments

Comments
 (0)