Merge pull request #15785 from eileenmcnaughton/contribution_url_params
[civicrm-core.git] / Civi / API / Subscriber / XDebugSubscriber.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 namespace Civi\API\Subscriber;
13
14 use Civi\API\Events;
15 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
17 /**
18 * Class XDebugSubscriber
19 * @package Civi\API\Subscriber
20 */
21 class XDebugSubscriber implements EventSubscriberInterface {
22
23 /**
24 * @return array
25 */
26 public static function getSubscribedEvents() {
27 return [
28 Events::RESPOND => ['onApiRespond', Events::W_LATE],
29 ];
30 }
31
32 /**
33 * @param \Civi\API\Event\RespondEvent $event
34 * API response event.
35 */
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
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 }
50
51 }