Debug.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods\Integrations\Query_Monitor\Collectors; |
| 4 | |
| 5 | // Don't load directly. |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | die( '-1' ); |
| 8 | } |
| 9 | |
| 10 | use QM_Backtrace; |
| 11 | use QM_DataCollector; |
| 12 | |
| 13 | /** |
| 14 | * Class Debug |
| 15 | * |
| 16 | * @since 3.2.7 |
| 17 | */ |
| 18 | class Debug extends QM_DataCollector { |
| 19 | |
| 20 | public $id = 'pods-debug'; |
| 21 | |
| 22 | /** |
| 23 | * The data to be tracked. |
| 24 | * |
| 25 | * @since 3.2.7 |
| 26 | * |
| 27 | * @var array |
| 28 | */ |
| 29 | protected static $custom_data = []; |
| 30 | |
| 31 | public function process() { |
| 32 | $this->data['debug_data'] = self::get_debug_data(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Track debug data. |
| 37 | * |
| 38 | * @since 3.2.7 |
| 39 | * |
| 40 | * @param mixed $debug The debug data to track. |
| 41 | * @param string $context The context where the debug came from. |
| 42 | * @param string $function The function/method name where the debug was called. |
| 43 | * @param int $line The line number where the debug was called. |
| 44 | */ |
| 45 | public static function track_debug_data( $debug, string $context, string $function, int $line ): void { |
| 46 | $trace = new QM_Backtrace( [ |
| 47 | 'ignore_hook' => [ |
| 48 | current_filter() => true, |
| 49 | ], |
| 50 | 'ignore_func' => [ |
| 51 | 'pods_debug_log_data' => true, |
| 52 | ], |
| 53 | ] ); |
| 54 | |
| 55 | self::$custom_data[] = compact( 'debug', 'context', 'function', 'line', 'trace' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get all of the debug data tracked. |
| 60 | * |
| 61 | * @since 3.2.7 |
| 62 | * |
| 63 | * @return array All of the debug data tracked. |
| 64 | */ |
| 65 | public static function get_debug_data(): array { |
| 66 | return self::$custom_data; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Reset all of the debug data tracked. |
| 71 | * |
| 72 | * @since 3.2.7 |
| 73 | */ |
| 74 | public static function reset_debug_data(): void { |
| 75 | self::$custom_data = []; |
| 76 | } |
| 77 | } |
| 78 |