Last active
March 15, 2016 23:09
-
-
Save s00d/65a4fc324943368fa449 to your computer and use it in GitHub Desktop.
Debug trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
trait Debug | |
{ | |
public static function xprint($param, $title = 'Debug information') { | |
ini_set('xdebug.var_display_max_depth', 50); | |
ini_set('xdebug.var_display_max_children', 25600); | |
ini_set('xdebug.var_display_max_data', 9999999999); | |
if (PHP_SAPI == 'cli') { | |
echo "\n---------------[ $title ]---------------\n"; | |
echo print_r( $param, true ); | |
echo "\n-------------------------------------------\n"; | |
} else { | |
$html = "<style> | |
.xprint-wrapper { | |
padding: 10px; | |
color: black; | |
background: #f6f6f6; | |
position: relative; | |
top: 18px; | |
border: 1px solid gray; | |
font-size: 11px; | |
font-family: InputMono, Monospace; | |
width: 80%; | |
margin: auto auto 25px auto; | |
} | |
.xprint-title { | |
padding-top: 1px; | |
color: #000; | |
background: #ddd; | |
position: relative; | |
top: -18px; | |
width: 170px; | |
height: 15px; | |
text-align: center; | |
border: 1px solid gray; | |
font-family: InputMono, Monospace; | |
} | |
.xprint-body { | |
color:#000; | |
} | |
</style> | |
<div class='xprint-wrapper'> | |
<div class='xprint-title'>$title</div> | |
<pre class='xprint-body'> " . htmlspecialchars( print_r($param, true) ) . "</pre> | |
</div>"; | |
echo $html; | |
} | |
} | |
public static function xd($val, $title = null) { | |
static::xprint($val, $title); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment