-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
396 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ecodev\Felix\DBAL\Logging; | ||
|
||
use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware; | ||
use Doctrine\DBAL\Driver\Result; | ||
use Doctrine\DBAL\Driver\Statement as DriverStatement; | ||
|
||
final class Connection extends AbstractConnectionMiddleware | ||
{ | ||
public function __construct(ConnectionInterface $connection) | ||
{ | ||
parent::__construct($connection); | ||
} | ||
|
||
public function prepare(string $sql): DriverStatement | ||
{ | ||
return new Statement(parent::prepare($sql), $sql); | ||
} | ||
|
||
public function query(string $sql): Result | ||
{ | ||
_log()->debug('Executing query: {sql}', ['sql' => $sql]); | ||
|
||
return parent::query($sql); | ||
} | ||
|
||
public function exec(string $sql): int|string | ||
{ | ||
_log()->debug('Executing statement: {sql}', ['sql' => $sql]); | ||
|
||
return parent::exec($sql); | ||
} | ||
|
||
public function beginTransaction(): void | ||
{ | ||
_log()->debug('Beginning transaction'); | ||
|
||
parent::beginTransaction(); | ||
} | ||
|
||
public function commit(): void | ||
{ | ||
_log()->debug('Committing transaction'); | ||
|
||
parent::commit(); | ||
} | ||
|
||
public function rollBack(): void | ||
{ | ||
_log()->debug('Rolling back transaction'); | ||
|
||
parent::rollBack(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ecodev\Felix\DBAL\Logging; | ||
|
||
use Doctrine\DBAL\Driver as DriverInterface; | ||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; | ||
use SensitiveParameter; | ||
|
||
final class Driver extends AbstractDriverMiddleware | ||
{ | ||
public function __construct(DriverInterface $driver) | ||
{ | ||
parent::__construct($driver); | ||
} | ||
|
||
public function connect(#[SensitiveParameter] array $params): Connection | ||
{ | ||
_log()->debug('Connecting to DB', $this->maskPassword($params)); | ||
|
||
return new Connection(parent::connect($params)); | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $params | ||
* | ||
* @return array<string,mixed> | ||
*/ | ||
private function maskPassword(#[SensitiveParameter] array $params): array | ||
{ | ||
if (isset($params['password'])) { | ||
$params['password'] = '***REDACTED***'; | ||
} | ||
|
||
return $params; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ecodev\Felix\DBAL\Logging; | ||
|
||
use Doctrine\DBAL\Driver as DriverInterface; | ||
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface; | ||
|
||
/** | ||
* Log SQL queries including their timing (so the query will be logged after its execution). | ||
*/ | ||
final class Middleware implements MiddlewareInterface | ||
{ | ||
public function wrap(DriverInterface $driver): DriverInterface | ||
{ | ||
return new Driver($driver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ecodev\Felix\DBAL\Logging; | ||
|
||
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware; | ||
use Doctrine\DBAL\Driver\Result; | ||
use Doctrine\DBAL\Driver\Statement as StatementInterface; | ||
use Doctrine\DBAL\ParameterType; | ||
|
||
final class Statement extends AbstractStatementMiddleware | ||
{ | ||
/** | ||
* @var array<int,mixed>|array<string,mixed> | ||
*/ | ||
private array $params = []; | ||
|
||
public function __construct( | ||
StatementInterface $statement, | ||
private readonly string $sql, | ||
) { | ||
parent::__construct($statement); | ||
} | ||
|
||
public function bindValue(int|string $param, mixed $value, ParameterType $type): void | ||
{ | ||
$this->params[$param] = $value; | ||
|
||
parent::bindValue($param, $value, $type); | ||
} | ||
|
||
public function execute(): Result | ||
{ | ||
$start = microtime(true); | ||
$result = parent::execute(); | ||
$end = microtime(true); | ||
|
||
_log()->debug($this->sql, [ | ||
'params' => $this->params, | ||
'time' => number_format(($end - $start) / 1000, 6), | ||
]); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.