Last active
February 1, 2017 12:21
-
-
Save zeraphie/73afb44750644521988b7031b2a83be2 to your computer and use it in GitHub Desktop.
A simple dump and exit function
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
if(!function_exists('d')){ | |
/** | |
* Short wrapper helper function for the junker debugger | |
*/ | |
function d(){ | |
$junker = new \Junker\Junker(); | |
$junker->withStyles = true; | |
$junker->withCloser = true; | |
$junker->d(func_get_args()); | |
} | |
} |
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 Junker; | |
/** | |
* Class Junker | |
* | |
* Dump some dismissable data - contains basic styles in order to help position | |
* the dump and make it clearer to use without | |
* clogging up some valuable screen space | |
*/ | |
class Junker { | |
const DEFAULTS_WITH_STYLES = false; | |
const DEFAULTS_WITH_CLOSER = false; | |
const DEFAULTS_WITH_EXIT = false; | |
public $withStyles = false; | |
public $withCloser = false; | |
public $withExit = false; | |
/** | |
* Junker constructor. | |
* | |
* @param bool $withStyles | |
* @param bool $withCloser | |
* @param bool $withExit | |
*/ | |
public function __construct( | |
$withStyles = self::DEFAULTS_WITH_STYLES, | |
$withCloser = self::DEFAULTS_WITH_CLOSER, | |
$withExit = self::DEFAULTS_WITH_EXIT | |
){ | |
$this->withStyles = (boolean) $withStyles; | |
$this->withCloser = (boolean) $withCloser; | |
$this->withExit = (boolean) $withExit; | |
} | |
/** | |
* Display junk | |
*/ | |
public function d(){ | |
if($this->withStyles){ | |
$this->addStyles(); | |
} | |
?> | |
<pre class="dump"> | |
<code> | |
<span class="dump-title"> | |
Dump data | |
<?php if($this->withCloser) : ?> | |
<span onclick="this.parentNode.parentNode.parentNode.remove()">close</span> | |
<?php endif; ?> | |
</span> | |
<?php | |
array_map( | |
function($dump){ | |
var_dump($dump); | |
}, | |
func_get_args() | |
); | |
?> | |
</code> | |
</pre> | |
<?php | |
if($this->withExit){ | |
exit; | |
} | |
} | |
/** | |
* Add styles to junk | |
*/ | |
private function addStyles(){ | |
?> | |
<style> | |
body { | |
margin: 0; | |
} | |
pre.dump { | |
background: #fff; | |
bottom: 0; | |
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); | |
font-family: monospace; | |
height: calc(50vh - 32px); | |
margin: 16px; | |
max-height: 600px; | |
left: 0; | |
overflow-y: auto; | |
padding: 16px; | |
position: fixed; | |
width: calc(100% - 32px); | |
z-index: 9999999999999999; | |
} | |
pre.dump:before, | |
pre.dump:after { | |
clear: both; | |
content: ''; | |
display: table; | |
} | |
pre.dump > code { | |
float: left; | |
margin: 0; | |
position: relative; | |
white-space: nowrap; | |
} | |
pre.dump > code > .dump-title { | |
display: block; | |
font-size: 20px; | |
margin-bottom: 12px; | |
} | |
pre.dump > code > .dump-title > span { | |
cursor: pointer; | |
background: rgba(0,0,0,0.3); | |
border-radius: 0.2em; | |
font-size: 16px; | |
padding: 3px 6px; | |
transition: background 0.3s; | |
} | |
pre.dump > code > .dump-title > span:hover { | |
background: rgba(0,0,0,0.15); | |
} | |
pre.dump > code > pre { | |
margin: 0; | |
} | |
</style> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment