3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\API\Subscriber
;
15 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
18 * Class XDebugSubscriber
19 * @package Civi\API\Subscriber
21 class XDebugSubscriber
implements EventSubscriberInterface
{
26 public static function getSubscribedEvents() {
28 Events
::RESPOND
=> ['onApiRespond', Events
::W_LATE
],
33 * @param \Civi\API\Event\RespondEvent $event
36 public function onApiRespond(\Civi\API\Event\RespondEvent
$event) {
37 $apiRequest = $event->getApiRequest();
38 $result = $event->getResponse();
39 if (function_exists('xdebug_time_index')
40 && \CRM_Utils_Array
::value('debug', $apiRequest['params'])
41 // result would not be an array for getvalue
44 $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage();
45 $result['xdebug']['memory'] = xdebug_memory_usage();
46 $result['xdebug']['timeIndex'] = xdebug_time_index();
47 $event->setResponse($result);