Added list of SQL statement to debug output
This commit is contained in:
parent
6bf8586735
commit
640b66a324
4 changed files with 20 additions and 3 deletions
|
@ -76,3 +76,4 @@ postsPerPage = 40
|
|||
[misc]
|
||||
thumbnailCropStyle = outside
|
||||
customFaviconUrl = /favicon.png
|
||||
dumpSqlIntoQueries = 0
|
||||
|
|
|
@ -4,12 +4,14 @@ namespace Szurubooru;
|
|||
final class Dispatcher
|
||||
{
|
||||
private $router;
|
||||
private $config;
|
||||
private $databaseConnection;
|
||||
private $authService;
|
||||
private $tokenService;
|
||||
|
||||
public function __construct(
|
||||
\Szurubooru\Router $router,
|
||||
\Szurubooru\Config $config,
|
||||
\Szurubooru\DatabaseConnection $databaseConnection,
|
||||
\Szurubooru\Helpers\HttpHelper $httpHelper,
|
||||
\Szurubooru\Services\AuthService $authService,
|
||||
|
@ -17,6 +19,7 @@ final class Dispatcher
|
|||
\Szurubooru\ControllerRepository $controllerRepository)
|
||||
{
|
||||
$this->router = $router;
|
||||
$this->config = $config;
|
||||
$this->databaseConnection = $databaseConnection;
|
||||
$this->httpHelper = $httpHelper;
|
||||
|
||||
|
@ -50,7 +53,11 @@ final class Dispatcher
|
|||
}
|
||||
$end = microtime(true);
|
||||
$json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime();
|
||||
if ($this->config->misc->dumpSqlIntoQueries)
|
||||
{
|
||||
$json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount();
|
||||
$json['__statements'] = $this->databaseConnection->getPDO()->getStatements();
|
||||
}
|
||||
|
||||
$this->httpHelper->setResponseCode($code);
|
||||
$this->httpHelper->setHeader('Content-Type', 'application/json');
|
||||
|
|
|
@ -4,10 +4,12 @@ namespace Szurubooru;
|
|||
class PDOEx extends \PDO
|
||||
{
|
||||
private $queryCount = 0;
|
||||
private $statements = [];
|
||||
|
||||
public function prepare($statement, $driverOptions = [])
|
||||
{
|
||||
++ $this->queryCount;
|
||||
$this->statements[] = $statement;
|
||||
return parent::prepare($statement, $driverOptions);
|
||||
}
|
||||
|
||||
|
@ -15,4 +17,9 @@ class PDOEx extends \PDO
|
|||
{
|
||||
return $this->queryCount;
|
||||
}
|
||||
|
||||
public function getStatements()
|
||||
{
|
||||
return $this->statements;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Szurubooru\Tests;
|
|||
final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||
{
|
||||
private $routerMock;
|
||||
private $configMock;
|
||||
private $httpHelperMock;
|
||||
private $authServiceMock;
|
||||
private $tokenServiceMock;
|
||||
|
@ -13,10 +14,12 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
$this->routerMock = $this->mock(\Szurubooru\Router::class);
|
||||
$this->configMock = $this->mockConfig();
|
||||
$this->httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
|
||||
$this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class);
|
||||
$this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class);
|
||||
$this->controllerRepositoryMock = $this->mock(\Szurubooru\ControllerRepository::class);
|
||||
$this->configMock->set('misc/dumpSqlIntoQueries', 0);
|
||||
}
|
||||
|
||||
public function testDispatchingArrays()
|
||||
|
@ -34,7 +37,6 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
$actual = $dispatcher->run('GET', '/');
|
||||
|
||||
unset($actual['__time']);
|
||||
unset($actual['__queries']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
@ -51,7 +53,6 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
$actual = $dispatcher->run('GET', '/');
|
||||
|
||||
unset($actual['__time']);
|
||||
unset($actual['__queries']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
@ -69,6 +70,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|||
{
|
||||
return new \Szurubooru\Dispatcher(
|
||||
$this->routerMock,
|
||||
$this->configMock,
|
||||
$this->databaseConnection,
|
||||
$this->httpHelperMock,
|
||||
$this->authServiceMock,
|
||||
|
|
Loading…
Reference in a new issue