2022-08-01 01:24:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-08-03 00:32:09 +02:00
|
|
|
use D3\DebugBar\Application\Component\DebugBarComponent;
|
2022-08-02 12:07:26 +02:00
|
|
|
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
|
2022-08-03 00:32:09 +02:00
|
|
|
use DebugBar\DataCollector\MessagesCollector;
|
2022-08-03 09:12:45 +02:00
|
|
|
use DebugBar\DebugBarException;
|
2022-08-03 00:32:09 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2022-08-02 12:07:26 +02:00
|
|
|
|
2022-08-03 09:12:45 +02:00
|
|
|
/**
|
|
|
|
* @param $sProfileName
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function startProfile(string $sProfileName): void
|
2022-08-01 01:24:44 +02:00
|
|
|
{
|
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
|
|
$trace[0] = $sProfileName;
|
|
|
|
$hash = md5(serialize($trace)).'-'.$sProfileName;
|
|
|
|
|
2022-08-02 12:07:26 +02:00
|
|
|
$timeDataCollector = TimeDataCollectorHandler::getInstance();
|
2022-08-01 01:24:44 +02:00
|
|
|
$timeDataCollector->startMeasure($hash, $sProfileName);
|
|
|
|
|
|
|
|
global $aStartTimes;
|
|
|
|
global $executionCounts;
|
|
|
|
if (!isset($executionCounts[$sProfileName])) {
|
|
|
|
$executionCounts[$sProfileName] = 0;
|
|
|
|
}
|
|
|
|
if (!isset($aStartTimes[$sProfileName])) {
|
|
|
|
$aStartTimes[$sProfileName] = 0;
|
|
|
|
}
|
|
|
|
$executionCounts[$sProfileName]++;
|
|
|
|
$aStartTimes[$sProfileName] = microtime(true);
|
|
|
|
}
|
|
|
|
|
2022-08-03 09:12:45 +02:00
|
|
|
/**
|
|
|
|
* @param string $sProfileName
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @throws DebugBarException
|
|
|
|
*/
|
|
|
|
function stopProfile(string $sProfileName): void
|
2022-08-01 01:24:44 +02:00
|
|
|
{
|
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
|
|
$trace[0] = $sProfileName;
|
|
|
|
$hash = md5(serialize($trace)).'-'.$sProfileName;
|
|
|
|
|
2022-08-02 12:07:26 +02:00
|
|
|
$timeDataCollector = TimeDataCollectorHandler::getInstance();
|
2022-08-01 01:24:44 +02:00
|
|
|
$timeDataCollector->stopMeasure($hash);
|
|
|
|
|
|
|
|
|
|
|
|
global $aStartTimes;
|
|
|
|
global $executionCounts;
|
|
|
|
if (!isset($executionCounts[$sProfileName])) {
|
|
|
|
$executionCounts[$sProfileName] = 0;
|
|
|
|
}
|
|
|
|
if (!isset($aStartTimes[$sProfileName])) {
|
|
|
|
$aStartTimes[$sProfileName] = 0;
|
|
|
|
}
|
|
|
|
$executionCounts[$sProfileName]++;
|
|
|
|
$aStartTimes[$sProfileName] = microtime(true);
|
2022-08-03 00:32:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-03 09:12:45 +02:00
|
|
|
/**
|
|
|
|
* @param mixed $mVar
|
|
|
|
* @param bool $blToFile
|
|
|
|
*
|
|
|
|
* @throws DebugBarException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function debugVar($mVar, bool $blToFile = false): void
|
2022-08-03 00:32:09 +02:00
|
|
|
{
|
|
|
|
if ($blToFile) {
|
|
|
|
$out = var_export($mVar, true);
|
|
|
|
$f = fopen(Registry::getConfig()->getConfigParam('sCompileDir') . "/vardump.txt", "a");
|
2022-08-03 09:12:45 +02:00
|
|
|
if (is_resource($f)) {
|
|
|
|
fwrite( $f, $out );
|
|
|
|
fclose( $f );
|
|
|
|
}
|
2022-08-03 00:32:09 +02:00
|
|
|
} else {
|
|
|
|
if (!isAdmin()) {
|
|
|
|
$activeView = Registry::getConfig()->getTopActiveView();
|
|
|
|
/** @var DebugBarComponent $debugBarComponent */
|
|
|
|
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
|
|
|
|
/** @var MessagesCollector $messages */
|
|
|
|
$messages = $debugBarComponent->getDebugBar()->getCollector('messages');
|
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
|
|
//$location = $trace[1]['class'] . '::' . $trace[1]['function']. '(' . $trace[0]['line'] . ')';
|
|
|
|
$location = $trace[1]['class'] . '::' . $trace[1]['function'];
|
|
|
|
$messages->addMessage($mVar, $location);
|
|
|
|
} else {
|
|
|
|
dumpVar($mVar, $blToFile);
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 01:24:44 +02:00
|
|
|
}
|