Last active
March 12, 2018 17:36
-
-
Save aryelgois/5635e8e6c9244d0a4f4ca6e983095113 to your computer and use it in GitHub Desktop.
Wraps the PHP Stack trace of a wab page you are developing for better visualization
This file contains 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
#!/usr/bin/env php | |
<?php | |
/** | |
* Wraps the PHP Stack trace of a wab page you are developing for better | |
* visualization | |
* | |
* Recomended usage: | |
* | |
* 1. Open your terminal and run | |
* | |
* while true; do ./stack_trace.php "[url]" > preview.md; sleep [sec]; done | |
* | |
* - Replace [url] by the one you are developing. Default: http://localhost/ | |
* - Replace [sec] by the frequence to update | |
* | |
* 2. Open the output file on Atom and enable Markdown Preview (ctrl-shift-m) | |
* | |
* 3. Optionally, put the preview in the bottom pane | |
* | |
* NOTE: | |
* - Remember to enable the Live Update in the package | |
* - It would be nice if the preview kept your scroll position.. You can kill | |
* the command in the terminal, analyze the preview, then rerun the command | |
* | |
* @author Aryel Mota Góis | |
* @license MIT | |
*/ | |
// read argument | |
$url = $argv[1] ?? 'http://localhost/'; | |
// load html | |
$html = file_get_contents($url); | |
// wrap PHP Stack trace | |
$start = strpos($html, "Stack trace:\n"); | |
if ($start !== false) { | |
$wrap = "<br />\n<pre><code>" | |
. substr($html, $start) | |
. '</code></pre>'; | |
$html = substr_replace($html, $wrap, $start); | |
} | |
// output | |
echo $html; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment