From: Tim Otten Date: Tue, 30 Nov 2021 23:54:41 +0000 (-0800) Subject: DebugSubscriber - Fix compatibility with XDebug 2/3 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=189cc9ff1eff1612e97eb528e5fab921a06ca868;p=civicrm-core.git DebugSubscriber - Fix compatibility with XDebug 2/3 --- diff --git a/Civi/API/Subscriber/DebugSubscriber.php b/Civi/API/Subscriber/DebugSubscriber.php index ac1abad894..0e6be75478 100644 --- a/Civi/API/Subscriber/DebugSubscriber.php +++ b/Civi/API/Subscriber/DebugSubscriber.php @@ -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 */ @@ -70,7 +93,7 @@ class DebugSubscriber implements EventSubscriberInterface { 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();