Created
February 16, 2017 15:18
-
-
Save Rayne/55e098e48a5742301671bee358e0be41 to your computer and use it in GitHub Desktop.
Fat-Free Framework with PHP Debugger Tracy
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
<?php | |
/** | |
* The following example combines Fat-Free Framework | |
* with the PHP Debugger (Toolbar) Tracy. | |
* | |
* @see https://github.com/bcosca/fatfree/issues/999 | |
*/ | |
use Tracy\Debugger; | |
require_once dirname(__DIR__) . '/vendor/autoload.php'; | |
Debugger::enable(null, dirname(__DIR__) . '/logs'); | |
$f3 = Base::instance(); | |
/** | |
* Forward errors and exceptions to Tracy. | |
*/ | |
$f3->set('ONERROR', function () use ($f3) { | |
Debugger::barDump($f3->get('ERROR'), 'ERROR'); | |
$e = $f3->get('EXCEPTION'); | |
// There isn't an exception when calling `Base->error()`. | |
if (!$e instanceof Throwable) { | |
$e = new Exception('HTTP ' . $f3->get('ERROR.code')); | |
} | |
Debugger::exceptionHandler($e); | |
}); | |
/** | |
* Routes and controllers. | |
*/ | |
$f3->route('GET /undefined-method', function (Base $f3, array $args = []) { | |
Debugger::barDump(['args' => $args], 'Controller Arguments'); | |
Debugger::log("Let's try to call an undefined method."); | |
(new stdClass)->undefinedMethod(); | |
}); | |
$f3->route('GET /status-400', function (Base $f3, array $args = []) { | |
$f3->error(400); | |
}); | |
$f3->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just a note, the "new" exception will then just be something like "http 500" and wont include the debug info. ran into this when trying to set up a route and the controller doesnt exist
it ends up as a tracy exception of:
yet the actual error is:
it seems F3 just calls
->error(500)
if it cant find the class for the->call()
so its not throwable when it kinda should be