Barebone\Inspector

<?php
//\Barebone\Inspector::setOff();
\Barebone\Inspector::setDefault('php');
\Barebone\Inspector::Inspect(['inspect'=>'this']);
?>    
array (
  'inspect' => 'this',
)

Usage

Simple Barebone\Inspector::Inspect
Barebone\Inspector::Inspect($somevar);

Will print $somevar into html as a <pre>-wrapped block formatted like JSON.

Return, Don't Print
$output = Barebone\Inspector::Inspect($somevar,true)

As with Barebone\Inspector::Inspect($somevar) except that the output is returned, captured in the $output variable and not printed.

Die Immediately After Debug Print
Barebone\Inspector::Inspect($somevar,"die")

Outputs the formatted $somevar and then dies.

Output as Html Comment
Barebone\Inspector::Inspect($somevar,"comment")

Outputs the formatted code in comment form. comments start <!--Barebone\Inspector::Inspect for easy searching.

Do not wrap in <pre> tags
Barebone\Inspector::Inspect($somevar,"nopre")

Outputs the formatted code without wrapping it in <pre> tags. Useful for console printing.

Print Included Files
Barebone\Inspector::Inspect($somefileref,'include)

Takes $somefileref as a file reference and includes that file's contents. Obviously, if the included file uses undefined variables then it will fail.

Also, the file reference must be absolute. For convenience a truepath function is included to get the real path. (PHP's realpath() function is a bit buggy, so best not use that. see http://stackoverflow.com/questions/4049856/replace-phps-realpath). e.g.

Barebone\Inspector::Inspect(truepath($somefileref),'include')
Output in JSON (Handy For Ajax)
Barebone\Inspector::Inspect($somevar,'json')

Returns the object in json notation. Handy when debugging over ajax that expects a json response.

Output in PHP (Handy For Purists ;))
Barebone\Inspector::Inspect($somevar,'php')

Returns the object in php notation. This then uses the var_export function instead of print_r. So the returned values here can even be interpreted directly as php variables.

Multiple Arguments

You can also collect multiple arguments together in a second argument array as follows:

Barebone\Inspector::Inspect($somevar,array("include","comment","return");

Or as a comma or space separated list:

Barebone\Inspector::Inspect($somevar,"include, comment, return");

You can even use dynamic arguments:

Barebone\Inspector::Inspect($somevar,"include","comment","return");
var_dump
Barebone\Inspector::Inspect($somevar,'dump');

This will run all data manipulation on $somevar (including if it is a file include), and then var_dump the result in addition to outputting in any other specified formatting.

Defaults

You can set defaults at a global level if you find yourself repeating the same optional arguments all the time.

Barebone\Inspector::setDefault($option);

Barebone\Inspector::getDefaults();

Barebone\Inspector::setDefaults($optionsArray);

Barebone\Inspector::removeDefault($option);	
Enabling/Disabling

Barebone\Inspector::Inspect statements will run by default, but you can control this by switching the functionality on and off globally, and querying the current state.

Barebone\Inspector::setOn() // switches this module on globally

Barebone\Inspector::setOff() // switches this module off globally

Barebone\Inspector::isOn() // return true if module is on, otherwise false
  • Barebone\Inspector

    Barebone\Inspector
    • [P] $enabled : bool
    • [P] $defaults : array
    • [M] setOn() : void
    • [M] setOff() : void
    • [M] isOn() : void
    • [M] setDefault( $key ) : void
    • [M] setDefaults( $defaults ) : void
    • [M] getDefaults() : void
    • [M] removeDefault( $key ) : void
    • [M] Inspect( $arr, $args ) : void