| 1 |
<?php |
| 2 |
|
| 3 |
namespace GeminiLabs\Blackbar; |
| 4 |
|
| 5 |
use DateTime; |
| 6 |
use ReflectionClass; |
| 7 |
|
| 8 |
class Console |
| 9 |
{ |
| 10 |
public $entries = array(); |
| 11 |
|
| 12 |
/** |
| 13 |
* @param string $message |
| 14 |
* @return static |
| 15 |
*/ |
| 16 |
public function store( $message, $location = '' ) |
| 17 |
{ |
| 18 |
$this->entries[] = array( |
| 19 |
'errno' => 0, |
| 20 |
'message' => $location.$this->normalizeValue( $message ), |
| 21 |
'name' => '<span class="glbb-info">Debug</span>', |
| 22 |
); |
| 23 |
return $this; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @param mixed $value |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
protected function isObjectOrArray( $value ) |
| 31 |
{ |
| 32 |
return is_object( $value ) || is_array( $value ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @param mixed $value |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
protected function normalizeValue( $value ) |
| 40 |
{ |
| 41 |
if( $value instanceof DateTime ) { |
| 42 |
$value = $value->format( 'Y-m-d H:i:s' ); |
| 43 |
} |
| 44 |
else if( $this->isObjectOrArray( $value )) { |
| 45 |
$value = print_r( json_decode( json_encode( $value )), true ); |
| 46 |
} |
| 47 |
else if( is_resource( $value )) { |
| 48 |
$value = (string)$value; |
| 49 |
} |
| 50 |
return esc_html( $value ); |
| 51 |
} |
| 52 |
} |
| 53 |
|