oxid-sql-logger/src/OxidEsalesDatabase.php

53 lines
1.8 KiB
PHP
Raw Normal View History

2019-08-20 23:34:33 +02:00
<?php
2019-09-19 19:52:54 +02:00
2019-08-20 23:34:33 +02:00
/**
2019-09-19 19:52:54 +02:00
* @author Tobias Matthaiou <developer@tobimat.eu>
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
2019-08-20 23:34:33 +02:00
*/
2019-09-19 19:52:54 +02:00
namespace D3\OxidSqlLogger;
2019-08-20 23:34:33 +02:00
use Doctrine\DBAL\Configuration;
/**
* Class OxidEsalesDatabase
* Is a depenction injection Helper Class
*/
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
{
public static function enableLogger($message = null)
2019-08-20 23:34:33 +02:00
{
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
2019-08-20 23:34:33 +02:00
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$dbalConfig = $database->getConnection()->getConfiguration();
$dbalConfig->setSQLLogger(
new OxidSQLLogger(
isset($trace[1]['file']) ? $trace[1]['file'] : null,
isset($trace[1]['line']) ? $trace[1]['line'] : null,
isset($trace[2]['class']) ? $trace[2]['class'] : null,
isset($trace[2]['function']) ? $trace[2]['function'] : null,
$message
)
);
}
/**
* @return OxidSQLLogger
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public static function getLogger()
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$dbalConfig = $database->getConnection()->getConfiguration();
return $dbalConfig->getSQLLogger();
2019-08-20 23:34:33 +02:00
}
public static function disableLogger()
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$dbalConfig = $database->getConnection()->getConfiguration();
$dbalConfig->setSQLLogger(null);
}
}