Skip to content

Commit

Permalink
Merge pull request #22197 from totten/master-xdebug3
Browse files Browse the repository at this point in the history
DebugSubscriber - Fix test-suite compatibility with XDebug 3
  • Loading branch information
totten authored Dec 1, 2021
2 parents 2cc768e + 189cc9f commit e65f2a8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Civi/API/Subscriber/DebugSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ class DebugSubscriber implements EventSubscriberInterface {
*/
private $debugLog;

/**
* @var bool
*/
private $enableStats;

public function __construct() {
$version = phpversion('xdebug');
switch ($version ? substr($version, 0, 2) : NULL) {
case '2.':
$this->enableStats = function_exists('xdebug_time_index');
break;

case '3.':
$xdebugMode = explode(',', ini_get('xdebug.mode'));
$this->enableStats = in_array('develop', $xdebugMode);
break;

default:
$this->enableStats = FALSE;
break;
}
}

/**
* @return array
*/
Expand Down Expand Up @@ -70,7 +93,7 @@ public function onApiRespond(\Civi\API\Event\RespondEvent $event) {
if (isset($this->debugLog) && $this->debugLog->getMessages()) {
$debug['log'] = $this->debugLog->getMessages();
}
if (function_exists('xdebug_time_index')) {
if ($this->enableStats) {
$debug['peakMemory'] = xdebug_peak_memory_usage();
$debug['memory'] = xdebug_memory_usage();
$debug['timeIndex'] = xdebug_time_index();
Expand Down

0 comments on commit e65f2a8

Please sign in to comment.