PHP Classes

ATK4 PHP Debug Bar: Output debug information using PHP DebugBar

Recommend this page to a friend!
  Info   View files Example   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 85 This week: 1All time: 10,006 This week: 560Up
Version License PHP version Categories
atk4-phpdebugbar 1.0.0MIT/X Consortium ...7Debug, Libraries, PHP 7
Collaborate with this project 

Author

atk4-phpdebugbar - github.com

Description

This package can be used to output debug information using PHP DebugBar.

It can integrate an application developed with ATK4 framework by adding the PHP debug bar output to the layout of a page generated by the application using the framework.

The package can pass the output of collectors components to the PHP Debug Bar like those for logging and database access, as well provide helper functions to simplify the integration of other collectors with the debug bar.

Innovation Award
PHP Programming Innovation award nominee
July 2019
Number 2


Prize: 1 Year Subscription to NomadPHP Advanced PHP Learning
DebugBar is an useful library that can be used to display interesting information for debugging purposes, so it helps developers fixing problems in their applications.

This package provides an integration of the PHP Debug Bar with applications that used the ATK4 framework, by providing collector classes that supply useful information about the applications' activity, like log data and database accesses.

Manuel Lemos
Picture of Francesco Danti
  Performance   Level  
Name: Francesco Danti <contact>
Classes: 7 packages by
Country: Italy Italy
Age: 46
All time rank: 3476138 in Italy Italy
Week rank: 411 Up18 in Italy Italy Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php

include 'bootstrap.php';

use
atk4\ui\App;

$app = new App([
   
'title' => 'Agile UI - DebugBar',
]);

$app->initLayout('Centered');
$app->add($debugBar = new ATK4PHPDebugBar\DebugBar());
$debugBar->setAssetsResourcesUrl('../');
$debugBar->addDefaultCollectors();

$loader = $app->add('Loader');

$loader->set(function ($l) {
   
$number = rand(1, 100);
   
$l->app->getDebugBarCollector('messages')->addMessage('new message :'.$number);

   
$l->add(['Text', 'random :'.$number]);
});

/** @var Button $button */
$button = $app->add(['Button', 'test']);
$button->on('click', function ($j) use ($loader) {
    return
$loader->jsReload();
});

$app->run();


Details

Build Status Codacy Badge Codacy Badge Test Coverage Maintainability

atk4-phpdebugbar

ATK4 With PHPDebugBar

First step :

install via composer : composer require abbadon1334/atk4-phpdebugbar

Use it in ATK

add to atk4\ui\App, just after initLayout :

$debugBar = $app->add(
    new ATK4PHPDebugBar\DebugBar()
)

Configure ATKDebugBar - Assets loading

PHPDebugBar needs to load his own assets (JS and CSS), you need to set the correct relative url :

$debugBar->setAssetsResourcesUrl('http://localhost/test');
/*
this will load :
 
 #CSS
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/font-awesome/css/font-awesome.min.css
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/highlightjs/styles/github.css
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/debugbar.css
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/widgets.css
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/openhandler.css
 
 #JS
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/highlightjs/highlight.pack.js
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/debugbar.js
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/widgets.js
 - http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/openhandler.js
*/ 

Configure phpdebugbar resource assets loading :

the asset url is composed by 3 parts : relative,

example : http://localhost/test/vendor/maximebf/debugbar/src/DebugBar/Resources/vendor/font-awesome/css/font-awesome.min.css

  • resource url = `http://localhost/test`
  • resource path = `/vendor/maximebf/debugbar/src/DebugBar/Resources`
  • debugbar path = `/vendor/font-awesome/css/font-awesome.min.css`

resource url and resource path can be defined with methods : - setAssetsResourcesUrl(string $url) - setAssetsResourcesPath(string $path)

Example if you use routing :

you have to define a route that serve PHPDebugBar assets :

$debugBar->setAssetsResourcesUrl('/');
$debugBar->setAssetsResourcesPath('debugbar/');

/*
this will load :
 - /debugbar/vendor/font-awesome/css/font-awesome.min.css
 - /debugbar/openhandler.js
*/

Adding Collectors

For general documentation, look in the really complete documentation of phpdebugbar : http://phpdebugbar.com/docs/data-collectors.html#using-collectors

Adding default Collectors

Add default collectors :

`$debugbar->addDefaultCollectors()`

OR

`$debugbar->addCollector(DebugBar\DataCollector\DataCollectorInterface $collector)`

ATK4 Logger Collector

if there is an already defined LoggerInterface in the app it will act as a proxy.

add it in this way : $debugBar->addATK4LoggerCollector()

To interact with the logger : - if your App implements DebugTrait any calls to LoggerInterface methods

example : `$app->info('test msg')`
 

- if your App implements or not DebugTrait , you can call it this way : $app->getDebugBarCollector('atk4-logger')->info('test'); or any other LoggerInterface methods

ATK4 Persistence\SQL Collector

- added in this way $debugBar->addATK4PersistenceSQLCollector();, it will add logging to $this->app->db ( $app->db must exists ). - added in this way $debugBar->addATK4PersistenceSQLCollector($persistence);, it will add logging to $persistence that must be instance of Persistence\SQL.

No interaction excepted, just add logs to PHPDebugBar of every call to PDO made by Persistence\SQL

Helpers

on Init, ATK4PHPDebugBar will add 3 dynamic methods to AppScope :

- getDebugBar() : \DebugBar\DebugBar


return object `\DebugBar\DebugBar`

- getDebugBarCollector($collector_name) : DebugBar\DataCollector\DataCollectorInterface


shorthand to `\DebugBar\DebugBar::getCollector`
  

- hasDebugBarCollector($collector_name) : bool;

shorthand to `\DebugBar\DebugBar::hasCollector`

TODO...

Add Unit Test and more examples


  Files folder image Files  
File Role Description
Files folder imagedemos (5 files)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (2 files)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .coveralls.yml Data Auxiliary data
Accessible without login Plain text file .phpmetrics.json Data Auxiliary data
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file renovate.json Data Auxiliary data

  Files folder image Files  /  demos  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file example-logger-debugTrait.php Class Class source
  Accessible without login Plain text file example-logger.php Example Example script
  Plain text file example-persistence.php Class Class source
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageCollector (1 file)
  Plain text file DebugBar.php Class Class source

  Files folder image Files  /  src  /  Collector  
File Role Description
  Plain text file ATK4Logger.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file DebugBarTest.php Class Class source
  Plain text file DemosTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:85
This week:1
All time:10,006
This week:560Up