Merge pull request #15475 from mecachisenros/externUrl
[civicrm-core.git] / Civi / API / Subscriber / XDebugSubscriber.php
CommitLineData
0661f62b
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
41498ac5 4 | Copyright CiviCRM LLC. All rights reserved. |
0661f62b 5 | |
41498ac5
TO
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 |
0661f62b 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
0661f62b
TO
11
12namespace Civi\API\Subscriber;
46bcf597 13
0661f62b
TO
14use Civi\API\Events;
15use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
6550386a
EM
17/**
18 * Class XDebugSubscriber
19 * @package Civi\API\Subscriber
20 */
0661f62b 21class XDebugSubscriber implements EventSubscriberInterface {
34f3bbd9 22
6550386a
EM
23 /**
24 * @return array
25 */
0661f62b 26 public static function getSubscribedEvents() {
c64f69d9
CW
27 return [
28 Events::RESPOND => ['onApiRespond', Events::W_LATE],
29 ];
0661f62b
TO
30 }
31
6550386a
EM
32 /**
33 * @param \Civi\API\Event\RespondEvent $event
8882ff5c 34 * API response event.
6550386a 35 */
8882ff5c 36 public function onApiRespond(\Civi\API\Event\RespondEvent $event) {
0661f62b
TO
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
42 && is_array($result)
43 ) {
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);
48 }
49 }
96025800 50
6550386a 51}