PluginProbe
WP Debugging / 2.11.13
WP Debugging v2.11.13
2.12.6 2.12.5 trunk 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.11.10 2.11.11 2.11.12 2.11.13 2.11.14 2.11.15 2.11.16 2.11.17 2.11.18 2.11.19 2.11.2 2.11.20 2.11.21 2.11.22 2.11.23 2.11.24 2.11.3 All 59 releases
wp-debugging / vendor / norcross / debug-quick-look / includes / parser.php

parser.php in WP Debugging 2.11.13, at vendor/norcross/debug-quick-look/includes/parser.php

139 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Our various parser functions.
4 *
5 * @package DebugQuickLook
6 */
7
8 // Call our namepsace.
9 namespace DebugQuickLook\Parser;
10
11 // Set our alias items.
12 use DebugQuickLook as Core;
13 use DebugQuickLook\Helpers as Helpers;
14 use DebugQuickLook\Formatting as Formatting;
15
16 /**
17 * Kick off our parsing action.
18 *
19 * @param boolean $parse Whether to actually parse the file.
20 *
21 * @return void
22 */
23 function run_parse( $parse = true ) {
24
25 // Check to see if we have our constant.
26 $hascon = Helpers\maybe_constant_set();
27
28 // If no constant is set, display that message.
29 if ( ! $hascon ) {
30 wp_die( __( 'You have not set the WP_DEBUG constant correctly.', 'debug-quick-look' ), __( 'Config Setup Error', 'debug-quick-look' ) );
31 }
32
33 // Add the new die handler.
34 add_filter( 'wp_die_handler', __NAMESPACE__ . '\die_handler' );
35
36 // Set our debug log file.
37 Helpers\check_debug_file();
38 $debug_file = Helpers\get_debug_file();
39
40 // If we didn't wanna parse the file, do it raw.
41 if ( ! $parse ) {
42
43 // Get our raw file.
44 $raw_debug = file_get_contents( $debug_file );
45
46 // And die with the raw.
47 wp_die( '<pre class="debug-quick-look-raw">' . $raw_debug . '</pre>', __( 'Viewing Raw Debug', 'debug-quick-look' ) );
48 }
49
50 // Parse it.
51 $parsed = parse_debug_file( $debug_file );
52
53 // And show the world.
54 wp_die( $parsed['display'], __( 'View Your File', 'debug-quick-look' ), array( 'totals' => absint( $parsed['totals'] ) ) );
55 }
56
57 /**
58 * Handle parsing our logfile.
59 *
60 * @param string $logfile Which log file we want to debug.
61 * @param string $order What order to display the entries.
62 *
63 * @return mixed
64 */
65 function parse_debug_file( $logfile = '', $order = 'asc' ) {
66
67 // Fetch the full lines.
68 $lines = file( $logfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
69
70 // Run a quick right trim on each line.
71 $lines = array_map( 'rtrim', $lines );
72
73 // Set our empty.
74 $setup = array();
75
76 // Set a marker for the proper lines.
77 $index = 0;
78
79 // Loop the lines.
80 foreach ( $lines as $nm => $linestring ) {
81
82 // Get our first character, which we test with.
83 $first = substr( $linestring, 0, 1 );
84
85 // Starting with the date bracket.
86 if ( '[' === esc_attr( $first ) ) {
87
88 // Set the line index, in case we need to append it.
89 $index = absint( $nm );
90
91 // Set the line as a new array element.
92 $setup[ $nm ] = $linestring;
93 }
94
95 // Now handle the non-bracket lines.
96 if ( '[' !== esc_attr( $first ) ) {
97
98 // Get our current line data.
99 $start = $setup[ $index ];
100
101 // Merge our current string with whatever we already had.
102 $merge = $start . PHP_EOL . $linestring;
103
104 // Add it to the merged string.
105 $setup[ $index ] = $merge;
106 }
107
108 // Should be done here.
109 }
110
111 // Reset the array keys.
112 $setup = array_values( $setup );
113
114 // Run our individual formatting.
115 $setup = Formatting\format_parsed_lines( $setup );
116
117 // If we wanted descending, swap.
118 if ( 'desc' === sanitize_text_field( $order ) ) {
119 $setup = array_reverse( $setup );
120 }
121
122 // Return an array of the markup and count.
123 return array(
124 'totals' => count( $setup ),
125 'display' => implode( "\n", $setup ),
126 );
127 }
128
129 /**
130 * Return our custom wp_die handler.
131 *
132 * @param string $die_handler The current handler.
133 *
134 * @return string
135 */
136 function die_handler( $die_handler ) {
137 return apply_filters( Core\HOOK_PREFIX . 'die_handler', '\DebugQuickLook\Handler\build_handler', $die_handler );
138 }
139