A simple class to add RedBeanPHP logged queries to Tracy's debug bar. Works with multiple databases.
All examples assume you have loaded RedBeanPHP and Tracy.
require 'RedBeanTracyPanel.php';
// Enable Tracy
Tracy\Debugger::enable(\Tracy\Debugger::DEVELOPMENT);
// Connect to your database
R::setup(...);
// Create a new panel, passing RedBean's name of the database as argument
// When using R::setup() the name of the database is 'default'
$panel = new RedBeanTracyPanel\Panel( 'default' );
// Set the title of the panel (optionnal)
$panel->setTitle('My awesome panel');
// Bind the panel to Tracy's debug bar
$panel->bind();
// Do your things, all queries will be retrieved at the end
You don't like the simple highlighting that RedBean's debug mode does ? Want to add something of your own ?
Here is an example using SqlFormatter
require 'RedBeanTracyPanel.php';
require 'SqlFormatter.php';
Tracy\Debugger::enable(\Tracy\Debugger::DEVELOPMENT);
R::setup(...);
$panel = new RedBeanTracyPanel\Panel( 'default' );
// To get the color right
SqlFormatter::$pre_attributes = 'style="color: black;"';
// To use SqlFormatter's highlight function in our panel
$panel->setHighlighter('SqlFormatter::highlight');
$panel->bind();
// Do your things, all queries will be retrieved at the end
sethighlighter
accepts a callable as its argument so you can create your own function and use it.
require 'RedBeanTracyPanel.php';
Tracy\Debugger::enable(\Tracy\Debugger::DEVELOPMENT);
R::addDatabase('My first db', ...);
$panel = new RedBeanTracyPanel\Panel( 'My First db' );
$panel->bind();
R::addDatabase('My other db', ...);
$panel = new RedBeanTracyPanel\Panel( 'My other db' );
$panel->bind();
// Do your things, all queries will be retrieved at the end
Used https://github.com/filisko/tracy-redbean as a starting point, and added support for multiple databases, custom highlighter and modified some things. However since I don't know anything about PSR-7 middleware or whatever, you won't find that here.
Feel free to add PRs !