Giter Site home page Giter Site logo

phpdeebuk's Introduction

phpDeeBuk

Debugger that outputs PHP data via JavaScript generated popup.

Getting started

<?php

class MyClass {
    public $Var2 = 'TM';
    private $Var1 = 'MK';
    
    const MY_CONST = 5979;
    
    public function add ($a, $b) {
        return $a + $b;
    }
}

?>
<html>
  <head>
    <title>phpDeeBuk example</title>
  </head>
  
  <body>
<?php
    $debugger = phpDeeBuk::getInstance();
    
    $myObj = new MyClass();
    $myVal = 5979;
    
    // analyze and dump data
    $debugger->analyze($myObj, 'My analyzed object')
             ->dump($myObj, 'My dumped object')
             ->analyze($myVal, 'My analyzed value')
             ->dump($myVal, 'My dumped value');
      
    // do unit tests       
    $debugger->assertTrue(1 == '1')  // ok
             ->assertFalse('2' == 2)  // fails
             ->assertEqual('3', 3)  // ok
             ->assertExact('3', 3)  // fails
             ->assertNotEqual('4', 4)  // fails
             ->assertNotExact('4', 4, 'My 2nd 4 value check')  // ok (with custom caption)
             
    // variables and console
    $debugger['myVar'] = 23979;
    $debugger->writeLine($debugger['myVar']);
    
    // create JavaScript code with HTML <script> tags
    $debugger->renderAndOutput();
?>
  </body>
</html>

Have a look at the examples:

Example

Analyze objects and values

class MyClass {
    public $Var2 = 'TM';
    private $Var1 = 'MK';
    
    const MY_CONST = 5979;
    
    public function add ($a, $b) {
        return $a + $b;
    }
}


$debugger = phpDeeBuk::getInstance();

$debugger->analyze(new MyClass())
         ->analyze(5979)
         ->analyze('TM', 'My string');  // define custom caption

Backtrace

You can output the current debug_backtrace() in a new tab:

$debugger = phpDeeBuk::getInstance();

$debugger->backtrace();

Console

Output data to a virtual console:

$debugger = phpDeeBuk::getInstance();

// outputs: Hello
//          world!
$debugger->writeLine('Hello')
         ->setForgroundColor('f00')  // set #f00 as text color in CSS format
         ->setBackgroundColor('yellow')
         ->writeFormat('%s', 'world')  // s. sprintf()
         ->resetColors()
         ->write('!');
         
// clear console
$debugger->clr();

Dump objects and values

Dump vars with var_export():

class MyClass {
    public $Var1 = 'TM';
    private $Var2 = 'MK';
}


$debugger = phpDeeBuk::getInstance();

$debugger->dump(new MyClass())
         ->dump(23979)
         ->dump('MK', 'My string');  // define custom caption

Multi instance

$defDbg = phpDeeBuk::getInstance();
$dbg1   = phpDeeBuk::getInstance('My debugger');  // new instance
$dbg2   = phpDeeBuk::getInstance();  // same instance as $defDbg

Test

Do simple unit tests:

class MyClass {
    public $Var1 = 'TM';
    private $Var2 = 'MK';
}


$debugger = phpDeeBuk::getInstance();

$debugger->assertTrue(1 == '1')  // ok
         ->assertFalse('2' == 2)  // fails
         ->assertEqual('3', 3)  // ok
         ->assertExact('3', 3)  // fails
         ->assertNotEqual('4', 4)  // fails
         ->assertNotExact('4', 4, 'My 2nd 4 value check')  // ok (with custom caption)

Variables

Work with variables:

$debugger = phpDeeBuk::getInstance();

$debugger->setVar('TM', 5979);
$var1 = $debugger->getVar('tm');   // var names are NOT case sensitive
                                   // other way: $var1 = $debugger['tm']

// other way: isset($debugger['MK'])
if (!$debugger->issetVar('MK')) {
    $debugger['mk'] = 23979;
}

// ['MK'] = 23979
// ['TM'] = 5979
$vars = $debugger->getVarArray();

// remove 'MK'
$debugger->unsetVar('Mk');
// other way: unset($debugger['Mk'])

$debugger->clearVars();

phpdeebuk's People

Contributors

mkloubert avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

bbehbudi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.