Initial commit
This commit is contained in:
parent
2a51da46c3
commit
a551e9b857
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/vendor/
|
19
README.md
Normal file
19
README.md
Normal file
@ -0,0 +1,19 @@
|
||||
Oxid SQL Logger
|
||||
---------------
|
||||
|
||||
Returns all SQL queries in the console browser.
|
||||
|
||||
## Install
|
||||
|
||||
composer require --dev tumtum/oxid-sql-logger
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
\StartSQLLog();
|
||||
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$list = $db->getAll('SELECT * FROM oxarticle WHERE oxprice < ? LIMIT 100', [49.99]);
|
||||
|
||||
\StopSQLLog();
|
||||
```
|
23
composer.json
Normal file
23
composer.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "tumtum/oxid-sql-logger",
|
||||
"description": "Returns all SQL queries in the browser.",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"monolog/monolog": "^1"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"tm\\oxid\\sql\\logger\\": "./src"
|
||||
},
|
||||
"files": [
|
||||
"./src/functions.php"
|
||||
]
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Tobias Matthaiou",
|
||||
"email": "developer@tobimat.eu"
|
||||
}
|
||||
]
|
||||
}
|
10
example/simple.php
Normal file
10
example/simple.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../../../../source/bootstrap.php';
|
||||
|
||||
\StartSQLLog();
|
||||
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$list = $db->getAll('SELECT * FROM oxarticle WHERE oxprice < ? LIMIT 100', [49.99]);
|
||||
|
||||
\StopSQLLog();
|
33
src/OxidEsalesDatabase.php
Normal file
33
src/OxidEsalesDatabase.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Autor: Tobias Matthaiou <developer@tobimat.eu>
|
||||
* Date: 2019-08-20
|
||||
* Time: 21:56
|
||||
*/
|
||||
|
||||
namespace tm\oxid\sql\logger;
|
||||
|
||||
use Doctrine\DBAL\Configuration;
|
||||
|
||||
/**
|
||||
* Class OxidEsalesDatabase
|
||||
* Is a depenction injection Helper Class
|
||||
*
|
||||
* @package tm\oxid\sql\logger
|
||||
*/
|
||||
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
|
||||
{
|
||||
public static function enableLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(new OxidSQLLogger());
|
||||
}
|
||||
|
||||
public static function disableLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(null);
|
||||
}
|
||||
}
|
54
src/OxidSQLLogger.php
Normal file
54
src/OxidSQLLogger.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Autor: Tobias Matthaiou <developer@tobimat.eu>
|
||||
* Date: 2019-08-20
|
||||
* Time: 21:33
|
||||
*/
|
||||
|
||||
namespace tm\oxid\sql\logger;
|
||||
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
use Monolog;
|
||||
|
||||
/**
|
||||
* Class OxidSQLLogger
|
||||
* @package tm\oxid\sql\logger
|
||||
*/
|
||||
class OxidSQLLogger implements SQLLogger
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!Monolog\Registry::hasLogger('sql')) {
|
||||
Monolog\Registry::addLogger(
|
||||
new Monolog\Logger(
|
||||
'sql',
|
||||
[
|
||||
new Monolog\Handler\BrowserConsoleHandler(),
|
||||
],
|
||||
[
|
||||
new Monolog\Processor\IntrospectionProcessor(Monolog\Logger::DEBUG, ['tm\\oxid\\sql\\logger', 'Doctrine\\DBAL\\Connection', 'OxidEsales\\EshopCommunity\\Core\\Database\\Adapter\\Doctrine\\Database']),
|
||||
new Monolog\Processor\PsrLogMessageProcessor(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function startQuery($sql, array $params = null, array $types = null)
|
||||
{
|
||||
Monolog\Registry::sql()->addDebug($sql, ['params' => $params, 'types' => $types]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function stopQuery()
|
||||
{
|
||||
}
|
||||
}
|
14
src/functions.php
Normal file
14
src/functions.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Autor: Tobias Matthaiou <developer@tobimat.eu>
|
||||
* Date: 2019-08-20
|
||||
* Time: 23:11
|
||||
*/
|
||||
|
||||
function StartSQLLog() {
|
||||
\tm\oxid\sql\logger\OxidEsalesDatabase::enableLogger();
|
||||
}
|
||||
|
||||
function StopSQLLog() {
|
||||
\tm\oxid\sql\logger\OxidEsalesDatabase::disableLogger();
|
||||
}
|
Loading…
Reference in New Issue
Block a user