From: Tim Otten Date: Fri, 21 Mar 2014 05:55:35 +0000 (-0700) Subject: CRM-14370 - API Kernel - Extract XDebugSubscriber X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0661f62b5e0a710c309a5e517221c0b81e9de60b;p=civicrm-core.git CRM-14370 - API Kernel - Extract XDebugSubscriber --- diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index 310fe8a917..29e41b805d 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -161,16 +161,6 @@ class Kernel { _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']); } - if (function_exists('xdebug_time_index') - && \CRM_Utils_Array::value('debug', $apiRequest['params']) - // result would not be an array for getvalue - && is_array($result) - ) { - $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); - $result['xdebug']['memory'] = xdebug_memory_usage(); - $result['xdebug']['timeIndex'] = xdebug_time_index(); - } - $responseEvent = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent(NULL, $apiRequest, $result)); $result = $responseEvent->getResponse(); diff --git a/Civi/API/Subscriber/XDebugSubscriber.php b/Civi/API/Subscriber/XDebugSubscriber.php new file mode 100644 index 0000000000..af23ecf41d --- /dev/null +++ b/Civi/API/Subscriber/XDebugSubscriber.php @@ -0,0 +1,53 @@ + array('onApiRespond', Events::W_LATE), + ); + } + + function onApiRespond(\Civi\API\Event\RespondEvent $event) { + $apiRequest = $event->getApiRequest(); + $result = $event->getResponse(); + if (function_exists('xdebug_time_index') + && \CRM_Utils_Array::value('debug', $apiRequest['params']) + // result would not be an array for getvalue + && is_array($result) + ) { + $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage(); + $result['xdebug']['memory'] = xdebug_memory_usage(); + $result['xdebug']['timeIndex'] = xdebug_time_index(); + $event->setResponse($result); + } + } +} \ No newline at end of file diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 954c5ef2e5..e849038456 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -87,6 +87,7 @@ class Container { */ public function createApiKernel($dispatcher) { $dispatcher->addSubscriber(new \Civi\API\Subscriber\TransactionSubscriber()); + $dispatcher->addSubscriber(new \Civi\API\Subscriber\XDebugSubscriber()); $dispatcher->addListener(\Civi\API\Events::AUTHORIZE, function($event) { // dummy placeholder $event->authorize();