| 1 |
<?php |
| 2 |
|
| 3 |
class DebugListener { |
| 4 |
|
| 5 |
/** |
| 6 |
* Store message and data for output. |
| 7 |
* |
| 8 |
* @var array |
| 9 |
*/ |
| 10 |
protected $data = array(); |
| 11 |
|
| 12 |
/** |
| 13 |
* Set default message and set var. |
| 14 |
* |
| 15 |
* @param string $message Message about the data. |
| 16 |
* @param mixed $data The data for debugging. |
| 17 |
*/ |
| 18 |
public function listen( $message, $data ) { |
| 19 |
if ( ! $message ) { |
| 20 |
$message = 'Debug in Console via Adminimize Plugin:'; |
| 21 |
} |
| 22 |
$this->data = array( $message, $data ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Print the message and data inside the console of the browser. |
| 27 |
*/ |
| 28 |
public function dump() { |
| 29 |
// Buffering. |
| 30 |
ob_start(); |
| 31 |
$output = ''; |
| 32 |
foreach ( $this->data as $entry ) { |
| 33 |
$output .= 'console.info(' . json_encode( $entry[0] ) . ');'; |
| 34 |
$output .= 'console.log(' . json_encode( $entry[1] ) . ');'; |
| 35 |
} |
| 36 |
|
| 37 |
echo sprintf( '<script>%s</script>', $output ); |
| 38 |
} |
| 39 |
} |
| 40 |
|