PHP code example of flightphp / tracy-extensions

1. Go to this page and download the library: Download flightphp/tracy-extensions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flightphp / tracy-extensions example snippets




use Tracy\Debugger;
use flight\debug\tracy\TracyExtensionLoader;

// bootstrap code
ugger::DEVELOPMENT)

// if you use database connections in your app, there is a 
// s a constructor compatible with PDO/SimplePdo.
$pdo = new PdoQueryCapture('sqlite:test.db', 'user', 'pass');
// or if you attach this to the Flight framework
Flight::register('db', PdoQueryCapture::class, ['sqlite:test.db', 'user', 'pass']);
// now whenever you make a query (via any method) it will capture the time, query, and parameters

// For full APM query tracking (beyond Tracy), install flightphp/apm and use:
// $db->logQueries() or enable via options; it fires the 'flight.db.queries' event.

// This connects the dots
if(Debugger::$showBar === true) {
	new TracyExtensionLoader(Flight::app());
}

// more code

Flight::start();



use flight\debug\tracy\TracyExtensionLoader;
use flight\debug\tracy\TwigTracyExtension;
use Tracy\Debugger;
use Twig\Environment;
use Twig\Extension\ProfilerExtension;
use Twig\Loader\FilesystemLoader;
use Twig\Profiler\Profile;

$loader = new FilesystemLoader(__DIR__ . '/views');
$twig = new Environment($loader, [
	'debug' => true,
	'cache' => false,
]);

// Optional: expose Tracy dump helpers in templates ({{ dump(var) }}, {{ bdump(var) }}, {{ dumpe(var) }})
$twig->addExtension(new TwigTracyExtension());

$tracyConfig = [];
if (Debugger::$showBar === true) {
	$profile = new Profile();
	$twig->addExtension(new ProfilerExtension($profile));
	$tracyConfig['twig_profile'] = $profile;
}

if (Debugger::$showBar === true) {
	new TracyExtensionLoader(Flight::app(), $tracyConfig);
}

// Map Flight::render() to Twig (example)
Flight::map('render', function (string $template, array $data = []) use ($twig) {
	if (substr($template, -5) !== '.twig') {
		$template .= '.twig';
	}
	echo $twig->render($template, $data);
});