From 189cc9ff1eff1612e97eb528e5fab921a06ca868 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 30 Nov 2021 15:54:41 -0800 Subject: [PATCH] DebugSubscriber - Fix compatibility with XDebug 2/3 --- Civi/API/Subscriber/DebugSubscriber.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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(); -- 2.25.1