Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additionally, deprecated `DebugStack` and `EchoSQLLogger` as per (my own) proposal in #2911 (comment)
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 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
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,37 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Logging; | ||
|
||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Logs every query as a debug message | ||
*/ | ||
final class PsrAdapter implements SQLLogger | ||
{ | ||
/** @var LoggerInterface */ | ||
private $logger; | ||
|
||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function startQuery($sql, array $params = null, array $types = null) | ||
{ | ||
$this->logger->debug($sql, [ | ||
'params' => $params, | ||
'types' => $types, | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function stopQuery() | ||
{ | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Logging; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use function class_exists; | ||
|
||
class PsrAdapterTest extends TestCase | ||
{ | ||
public function testLogging() | ||
{ | ||
if (! class_exists(LoggerInterface::class)) { | ||
$this->markTestSkipped('PSR-3 LoggerInterface is unavailable'); | ||
} | ||
|
||
$logger = $this->createMock(LoggerInterface::class); | ||
$logger->expects($this->once()) | ||
->method('debug') | ||
->with('SELECT name FROM users WHERE id = ?', [ | ||
'params' => [1], | ||
'types' => [ParameterType::INTEGER], | ||
]); | ||
|
||
$adapter = new PsrAdapter($logger); | ||
$adapter->startQuery('SELECT name FROM users WHERE id = ?', [1], [ParameterType::INTEGER]); | ||
} | ||
} |