Skip to content

A simple class to add RedBeanPHP logged queries to Tracy's debug bar.

License

Notifications You must be signed in to change notification settings

Lynesth/redbean-tracy-panel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

RedBeanTracyPanel

A simple class to add RedBeanPHP logged queries to Tracy's debug bar. Works with multiple databases.

Usage

All examples assume you have loaded RedBeanPHP and Tracy.

Simple example

  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

firefox_2018-05-23_17-25-15

Setting your own highlighter

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

firefox_2018-05-23_17-26-01

sethighlighter accepts a callable as its argument so you can create your own function and use it.

Using multiple databases

  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

firefox_2018-05-23_17-21-32

Disclaimer

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 !

About

A simple class to add RedBeanPHP logged queries to Tracy's debug bar.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages