|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Page Framework |
|
4
|
|
|
* |
|
5
|
|
|
* http://en.michaeluno.jp/admin-page-framework/ |
|
6
|
|
|
* Copyright (c) 2013-2016 Michael Uno; Licensed MIT |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Provides debugging methods. |
|
12
|
|
|
* |
|
13
|
|
|
* Use the methods of this class to check variable contents. |
|
14
|
|
|
* |
|
15
|
|
|
* @image http://admin-page-framework.michaeluno.jp/image/common/utility/debug.png |
|
16
|
|
|
* @since 2.0.0 |
|
17
|
|
|
* @since 3.1.3 Extends AdminPageFramework_WPUtility |
|
18
|
|
|
* @since 3.7.1 Extends AdminPageFramework_FrameworkUtility |
|
19
|
|
|
* @extends AdminPageFramework_FrameworkUtility |
|
20
|
|
|
* @package AdminPageFramework |
|
21
|
|
|
* @subpackage Common/Utility |
|
22
|
|
|
*/ |
|
23
|
|
|
class AdminPageFramework_Debug extends AdminPageFramework_Debug_Log { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Prints out the given variable contents |
|
27
|
|
|
* |
|
28
|
|
|
* If a file pass is given to the second parameter, it saves the output in the file. |
|
29
|
|
|
* |
|
30
|
|
|
* @since 3.2.0 |
|
31
|
|
|
* @remark An alias of the dumpArray() method. |
|
32
|
|
|
* @param array|string $asArray The variable to check its contents. |
|
33
|
|
|
* @param string $sFilePath The file path for a log file. |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
static public function dump( $asArray, $sFilePath=null ) { |
|
|
|
|
|
|
37
|
|
|
echo self::get( $asArray, $sFilePath ); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns a string representation of a given value with details. |
|
42
|
|
|
* @since 3.8.9 |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
static public function getDetails( $mValue, $bEscape=true ) { |
|
|
|
|
|
|
46
|
|
|
$_sValueWithDetails = self::_getArrayRepresentationSanitized( |
|
47
|
|
|
self::_getLegibleDetails( $mValue ) |
|
48
|
|
|
); |
|
49
|
|
|
return $bEscape |
|
50
|
|
|
? "<pre class='dump-array'>" |
|
51
|
|
|
. htmlspecialchars( $_sValueWithDetails ) |
|
52
|
|
|
. "</pre>" |
|
53
|
|
|
: $_sValueWithDetails; // non-escape is used for exporting data into file. |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Retrieves the output of the given variable contents. |
|
58
|
|
|
* |
|
59
|
|
|
* If a file pass is given to the second parameter, it saves the output in the file. |
|
60
|
|
|
* |
|
61
|
|
|
* @remark An alias of getArray() method. |
|
62
|
|
|
* @since 3.2.0 |
|
63
|
|
|
* @param array|string $asArray The variable to check its contents. |
|
64
|
|
|
* @param string $sFilePath The file path for a log file. |
|
65
|
|
|
* @param boolean $bEscape Whether to escape characters. |
|
66
|
|
|
*/ |
|
67
|
|
|
static public function get( $asArray, $sFilePath=null, $bEscape=true ) { |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
if ( $sFilePath ) { |
|
|
|
|
|
|
70
|
|
|
self::log( $asArray, $sFilePath ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $bEscape |
|
74
|
|
|
? "<pre class='dump-array'>" |
|
75
|
|
|
. htmlspecialchars( self::_getLegible( $asArray ) ) // `esc_html()` breaks with complex HTML code. |
|
76
|
|
|
. "</pre>" |
|
77
|
|
|
: self::_getLegible( $asArray ); // non-escape is used for exporting data into file. |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Logs the given variable output to a file. |
|
83
|
|
|
* |
|
84
|
|
|
* <h4>Example</h4> |
|
85
|
|
|
* <code> |
|
86
|
|
|
* $_aValues = array( 'foo', 'bar' ); |
|
87
|
|
|
* AdminPageFramework_Debug::log( $aValues ); |
|
88
|
|
|
* </code> |
|
89
|
|
|
* |
|
90
|
|
|
* @remark The alias of the `logArray()` method. |
|
91
|
|
|
* @since 3.1.0 |
|
92
|
|
|
* @since 3.1.3 Made it leave milliseconds and elapsed time from the last call of the method. |
|
93
|
|
|
* @since 3.3.0 Made it indicate the data type. |
|
94
|
|
|
* @since 3.3.1 Made it indicate the data length. |
|
95
|
|
|
* @param mixed $mValue The value to log. |
|
96
|
|
|
* @param string $sFilePath The log file path. |
|
97
|
|
|
* @return void |
|
98
|
|
|
**/ |
|
99
|
|
|
static public function log( $mValue, $sFilePath=null ) { |
|
|
|
|
|
|
100
|
|
|
self::_log( $mValue, $sFilePath ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/* Deprecated Methods */ |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Prints out the given variable contents. |
|
107
|
|
|
* |
|
108
|
|
|
* If a file pass is given, it saves the output in the file. |
|
109
|
|
|
* |
|
110
|
|
|
* @since unknown |
|
111
|
|
|
* @deprecated 3.2.0 |
|
112
|
|
|
*/ |
|
113
|
|
|
static public function dumpArray( $asArray, $sFilePath=null ) { |
|
|
|
|
|
|
114
|
|
|
self::showDeprecationNotice( 'AdminPageFramework_Debug::' . __FUNCTION__, 'AdminPageFramework_Debug::dump()' ); |
|
115
|
|
|
AdminPageFramework_Debug::dump( $asArray, $sFilePath ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Retrieves the output of the given array contents. |
|
120
|
|
|
* |
|
121
|
|
|
* If a file pass is given, it saves the output in the file. |
|
122
|
|
|
* |
|
123
|
|
|
* @since 2.1.6 The $bEncloseInTag parameter is added. |
|
124
|
|
|
* @since 3.0.0 Changed the $bEncloseInTag parameter to bEscape. |
|
125
|
|
|
* @deprecated 3.2.0 |
|
126
|
|
|
*/ |
|
127
|
|
|
static public function getArray( $asArray, $sFilePath=null, $bEscape=true ) { |
|
|
|
|
|
|
128
|
|
|
self::showDeprecationNotice( 'AdminPageFramework_Debug::' . __FUNCTION__, 'AdminPageFramework_Debug::get()' ); |
|
129
|
|
|
return AdminPageFramework_Debug::get( $asArray, $sFilePath, $bEscape ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Logs the given array output into the given file. |
|
134
|
|
|
* |
|
135
|
|
|
* @since 2.1.1 |
|
136
|
|
|
* @since 3.0.3 Changed the default log location and file name. |
|
137
|
|
|
* @deprecated 3.1.0 Use the `log()` method instead. |
|
138
|
|
|
*/ |
|
139
|
|
|
static public function logArray( $asArray, $sFilePath=null ) { |
|
|
|
|
|
|
140
|
|
|
self::showDeprecationNotice( 'AdminPageFramework_Debug::' . __FUNCTION__, 'AdminPageFramework_Debug::log()' ); |
|
141
|
|
|
AdminPageFramework_Debug::log( $asArray, $sFilePath ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Returns a string representation of the given value. |
|
146
|
|
|
* @since 3.5.0 |
|
147
|
|
|
* @param mixed $mValue The value to get as a string |
|
148
|
|
|
* @internal |
|
149
|
|
|
* @return string |
|
150
|
|
|
* @deprecated 3.8.9 |
|
151
|
|
|
*/ |
|
152
|
|
|
static public function getAsString( $mValue ) { |
|
|
|
|
|
|
153
|
|
|
self::showDeprecationNotice( 'AdminPageFramework_Debug::' . __FUNCTION__ ); |
|
154
|
|
|
return self::_getLegible( $mValue ); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|