Methods This class defines the following methods:

static isCli () -> bool

Checks if PHP is running from CLI (command line interface).

Example:

 echo \MD\Foundation\Debug\Debugger::isCli();
 // -> true or false
Returns:
bool

static isWebRequest () -> bool

Checks if PHP is running from a web request (as opposed to CLI).

Example:

 echo |MD\Foundation\Debug\Debugger::isWebRequest();
 // -> true or false
Returns:
bool

static getType (mixed $var) -> string

Returns type of the given variable.

Similiar to PHP's gettype() function, but instead of object it will return an actual class name.

Example:

 use \MD\Foundation\Debug\Debugger;

 echo Debugger::getType(1);
 // -> integer

 echo Debugger::getType('Lorem ipsum');
 // -> string

 echo Debugger::getType(array());
 // -> array

 $obj = new stdObject();
 echo Debugger::getType($obj);
 // -> stdObject
Arguments:
mixed $var

Variable to be checked.

Returns:
string

static getClass (object|string $object, bool $stripNamespace = false) -> string

Returns the name of the passed object's class.

Example:

 use \MD\Foundation\Debug\Debugger;

 $obj = new \Psr\Log\NullLogger();
 echo Debugger::getClass($obj);
 // -> Psr\Log\NullLogger

 echo Debugger::getClass($obj, true);
 // -> NullLogger

 echo Debugger::getClass('Psr\Log\NullLogger');
 // -> Psr\Log\NullLogger

 echo Debugger::getClass('Psr\Log\NullLogger', true);
 // -> NullLogger
Arguments:
object|string $object

Will also accept a string (name of a class) but will return it untouched.

bool $stripNamespace

[optional] Should only base class name be returned, void of namespace? Default: false.

Returns:
string

static getNamespace (object|string $object) -> string

Returns namespace for the given object or class, without the class name itself.

Example:

 use \MD\Foundation\Debug\Debugger;

 $obj = new \Psr\Log\NullLogger();
 echo Debugger::getNamespace($obj);
 // -> Psr\Log

 echo Debugger::getNamespace('Psr\Log\NullLogger');
 // -> Psr\Log
Arguments:
object|string $object

Will also accept a string (name of a class).

Returns:
string

static getClassFile (object $object) -> string|bool

Returns a path to a file where the class of the given object was defined.

Example:

 use \MD\Foundation\Debug\Debugger;

 $obj = new \Psr\Log\NullLogger();
 echo Debugger::getClassFile($obj);
 // -> /var/www/homepage/vendor/psr/log/Psr/Log/NullLogger.php

 echo Debugger::getClassFile('Psr\Log\NullLogger');
 // -> /var/www/homepage/vendor/psr/log/Psr/Log/NullLogger.php

Returns false if failed to determine the file.

Arguments:
object $object
Returns:
string|bool

static getObjectAncestors (object|string $object) -> array

Returns a list of ancestors of the given object in an array.

Example:

 $logger = new \Psr\Log\NullLogger();
 echo \MD\Foundation\Debug\Debugger::getObjectAncestors($logger);
 // -> array('Psr\Log\AbstractLogger')

 echo \MD\Foundation\Debug\Debugger::getObjectAncestors('\Psr\Log\NullLogger');
 // -> array('Psr\Log\AbstractLogger')
Arguments:
object|string $object

Object or string name of a class.

Returns:
array

static isImplementing (object|string $class, string $interface) -> bool

Checks whether the given class or object implements the interface.

Example:

 echo \MD\Foundation\Debug\Debugger::isImplementing('Psr\Log\NullLogger', 'Psr\Log\LoggerInterface');
 // -> true
Arguments:
object|string $class

Either an object or a string name of the class.

string $interface

Name of the interface to check.

Returns:
bool

static isExtending (object|string $class, string $parent, bool $includeSelf = false) -> bool

Checks if the given class or object extends the given class.

Example:

 echo \MD\Foundation\Debug\Debugger::isExtending('Psr\Log\NullLogger', 'stdObject');
 // -> false
Arguments:
object|string $class

Either an object or a string name of the class.

string $parent

Name of the parent class to check.

bool $includeSelf

[optional] If set to true, it will also check if $class is $parent. Default: false.

Returns:
bool

static callableToString (callable $callable) -> string

Converts the given PHP callable to a string that should contain its name.

Not implemented yet

Arguments:
callable $callable
Returns:
string
Throws:
MD\Foundation\Exceptions\NotImplementedException

This method is not yet implemented.

static dump ()

Friendly output of variables.

It will print them out in <pre class="md-dump"> tag.

It will dump all arguments sent to this function.

If PHP is running from CLI then it will dump all the arguments in one line separated by spaces.

There is a shortcut alias function \MD\dump().

static stringDump () -> string

Returns a string containing HTML formatted information about the passed variable.

There is a shortcut alias function \MD\string_dump().

Returns:
string

static consoleDump ()

Dumps all the arguments into browser's JavaScript console.

Attempts to convert all objects into arrays.

There are two shortcut alias functions \MD\console_dump() and \MD\console_log().

static consoleStringDump () -> string

Returns a string containing JavaScript code that will log all the arguments into browser's JavaScript console.

Attempts to convert all objects into arrays.

There is a shortcut alias function \MD\console_string_dump().

Returns:
string

static getPrettyTrace (array $trace) -> array

"Prettifies" the stack trace array to include less fields by combining some of them.

Example:

 $trace = debug_backtrace();
 echo \MD\Foundation\Debug\Debugger::getPrettyTrace($trace);
 // -> array(array('function' => ..., 'file' => ..., 'arguments' => ...)), ...)
Arguments:
array $trace

Original trace array.

Returns:
array

static handleException (MD\Foundation\Debug\Exception $e, array $log = array(), int $httpResponseCode = 500)

Handles an exception by printing it out nicely.

Arguments:
MD\Foundation\Debug\Exception $e

Exception that you want to handle.

array $log

[optional] Any log to be attached to the error page.

int $httpResponseCode

[optional] What HTTP response code to use? Default: 500.

static handleError (int $code, string $message, string $file, int $line, array $context) -> bool

Custom error handler.

Arguments:
int $code

Error code.

string $message

Error message.

string $file

Path to the file in which the error occurred.

int $line

Line number of the file in which the error occurred.

array $context

The error's context.

Returns:
bool

static handleFatalError ()

Handles a fatal error.