Skip to content

Commit

Permalink
debugbar compat
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Sep 16, 2022
1 parent 587ca54 commit 51ac1bb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions _config.php
@@ -1,5 +1,6 @@
<?php

use LeKoala\DebugBar\DebugBar;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Environment;
Expand All @@ -12,14 +13,27 @@ function bm($cb = null)
}
}
// Add a debug helper
if (!function_exists('d')) {
if (!function_exists('d') && !class_exists(DebugBar::class)) {
function d(...$args)
{
// Don't show on live
if (Director::isLive()) {
return;
}

$doExit = true;

// Allow testing the helper
if (isset($args[0]) && $args[0] instanceof \SilverStripe\Dev\SapphireTest) {
$doExit = false;
array_shift($args);
} else {
// Clean buffer that may be in the way
if (ob_get_contents()) {
ob_end_clean();
}
}

$debugView = \SilverStripe\Dev\Debug::create_debug_view();
// Also show latest object in backtrace
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT) as $row) {
Expand All @@ -35,7 +49,9 @@ function d(...$args)
echo $debugView->debugVariable($val, \SilverStripe\Dev\Debug::caller(), true, $i);
$i++;
}
exit();
if ($doExit) {
exit();
}
}
}
// Add a logger helper
Expand Down

0 comments on commit 51ac1bb

Please sign in to comment.