1515 * @license GNU-2.0+
1616 */
1717
18- use Symfony \Component \VarDumper \Cloner \VarCloner ;
19- use Symfony \Component \VarDumper \Dumper \HtmlDumper ;
20- use Symfony \Component \VarDumper \VarDumper ;
21- use function KnowTheCode \DebugToolkit \_get_plugin_root_dir ;
18+ use KnowTheCode \DebugToolkit \VarDumper_Helpers ;
19+
20+ require_once __DIR__ . '/class-vardumper.php ' ;
2221
2322if ( ! function_exists ( 'vdump ' ) ) {
2423 /**
2726 * @since 1.0.0
2827 *
2928 * @param mixed $var Variable to dump.
30- *
31- * @throws InvalidArgumentException If no arguments are passed, throws an error.
3229 */
3330 function vdump ( $ var ) {
34- _dump_var ( $ var, __FUNCTION__ );
31+ VarDumper_Helpers:: dump ( $ var );
3532 }
3633}
3734
@@ -42,11 +39,9 @@ function vdump( $var ) {
4239 * @since 1.0.0
4340 *
4441 * @param mixed $var Variable to dump.
45- *
46- * @throws InvalidArgumentException If no arguments are passed, throws an error.
4742 */
4843 function vd ( $ var ) {
49- _dump_var ( $ var , __FUNCTION__ );
44+ VarDumper_Helpers:: dump ( $ var , __FUNCTION__ );
5045 }
5146}
5247
@@ -57,12 +52,9 @@ function vd( $var ) {
5752 * @since 1.0.0
5853 *
5954 * @param mixed $var Variable to dump.
60- *
61- * @throws InvalidArgumentException If no arguments are passed, throws an error.
6255 */
6356 function vdd ( $ var ) {
64- _dump_var ( $ var , __FUNCTION__ );
65- die ();
57+ VarDumper_Helpers::dump_and_die ( $ var );
6658 }
6759}
6860
@@ -73,105 +65,8 @@ function vdd( $var ) {
7365 * @since 1.0.0
7466 *
7567 * @param mixed $var Variable to dump.
76- *
77- * @throws InvalidArgumentException If no arguments are passed, throws an error.
7868 */
7969 function vddd ( $ var ) {
80- _dump_var ( $ var , __FUNCTION__ );
81- die ();
82- }
83- }
84-
85- /**
86- * Run the var dumper.
87- *
88- * @since 1.0.0
89- * @access private
90- *
91- * @param mixed $var Variable to dump.
92- * @param string $func_name Name of the calling function.
93- *
94- * @throws InvalidArgumentException If no arguments are passed, throws an error.
95- */
96- function _dump_var ( $ var , $ func_name ) {
97-
98- if ( empty ( $ var ) ) {
99- $ message = __ ( 'No variable passed to the VarDumper function ' , 'devtoolkit ' );
100- throw new InvalidArgumentException ( esc_html ( "{$ message } {$ func_name }" ) );
101- die ();
102- }
103-
104- _set_html_dumper_styles ();
105- VarDumper::dump ( $ var );
106- }
107-
108- /**
109- * Sets the VarDumper HTML Dumper's styles.
110- *
111- * @since 1.0.0
112- * @access private
113- *
114- * @return null bails out when cli or handler is already set.
115- */
116- function _set_html_dumper_styles () {
117- static $ handler = null ;
118-
119- // Bail out.
120- if ( in_array ( PHP_SAPI , [ 'cli ' , 'phpdbg ' ], true ) ) {
121- return ;
122- }
123-
124- if ( null !== $ handler ) {
125- return ;
70+ VarDumper_Helpers::dump_and_die ( $ var );
12671 }
127-
128- $ cloner = new VarCloner ();
129- $ dumper = new HtmlDumper ();
130-
131- $ dumper ->setStyles ( _get_vardumper_config ( 'styles ' ) );
132- $ handler = function ( $ var ) use ( $ cloner , $ dumper ) {
133- $ dumper ->dump ( $ cloner ->cloneVar ( $ var ) );
134- };
135-
136- VarDumper::setHandler ( $ handler );
137- }
138-
139- /**
140- * Gets the VarDumper's configuration or a specific configuration parameter.
141- *
142- * @since 1.0.0
143- * @access private
144- *
145- * @param string $key Optional. Parameter's key to return.
146- *
147- * @return mixed
148- * @throw InvalidArgumentException If the key does not exist, an error is thrown.
149- */
150- function _get_vardumper_config ( $ key = '' ) {
151- static $ config = null ;
152-
153- if ( empty ( $ config ) ) {
154- /**
155- * Filter the VarDumper configuration parameters.
156- *
157- * @since 1.0.0
158- *
159- * @param array Array of configuration parameters for the VarDump component.
160- */
161- $ config = apply_filters ( 'set_html_dumper_config ' , (array ) require _get_plugin_root_dir () . '/config/var-dumper.php ' );
162- }
163-
164- if ( empty ( $ key ) ) {
165- return $ config ;
166- }
167-
168- if ( ! array_key_exists ( $ key , $ config ) ) {
169- $ message = __ ( 'The key [$s] does not exist in the config: ' , 'devtoolkit ' );
170- $ message = sprintf ( $ message , $ key );
171- throw new InvalidArgumentException (
172- esc_html ( $ message . ': ' ) . print_r ( $ config , true )
173- );
174- }
175-
176- return $ config [ $ key ];
17772}
0 commit comments