Skip to content

Instantly share code, notes, and snippets.

@Rayne
Created February 16, 2017 15:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rayne/55e098e48a5742301671bee358e0be41 to your computer and use it in GitHub Desktop.
Save Rayne/55e098e48a5742301671bee358e0be41 to your computer and use it in GitHub Desktop.
Fat-Free Framework with PHP Debugger Tracy
<?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();
@WilliamStam
Copy link

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

$this->f3->route("GET /", function($app, $params) {
	$app->call("\\app\\web\\controllers\\home->page");
});

it ends up as a tracy exception of:

Exception
HTTP 500 search►

yet the actual error is:

Fatal error: Class 'app\web\controllers\_' not found in D:\Work\project\app\web\controllers\home.php on line 5 Call Stack: 0.0018 412816 1. {main}() D:\Work\project\public\index.php:0 0.0407 2327608 2. include_once('D:\Work\project\app\web\_.php') D:\Work\project\public\index.php:6 0.0412 2331912 3. include('D:\Work\project\app\web\controllers\home.php') D:\Work\project\app\web\_.php:4 

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment