Debugger Class Info:

Class Declaration:

class Debugger

File name:
Cake/Utility/Debugger.php
Description:

Provide custom logging and error handling.

Debugger overrides PHP's default error handling to provide stack traces and enhanced logging

Properties:

  • _data string

    Holds current output data when outputFormat is false.

  • errors array

    A list of errors generated by the application.

  • _outputFormat string

    The current output format.

  • _templates string

    Templates used when generating trace or error strings. Can be global or indexed by the format value used in $_outputFormat.

addFormat

top

Add an output format or update a format in Debugger.

Debugger::addFormat('custom', $data);

Where $data is an array of strings that use String::insert() variable replacement. The template vars should be in a {:id} style. An error formatter can have the following keys:

  • 'error' - Used for the container for the error message. Gets the following template variables: id, error, code, description, path, line, links, info
  • 'info' - A combination of code, context and trace. Will be set with the contents of the other template keys.
  • 'trace' - The container for a stack trace. Gets the following template variables: trace
  • 'context' - The container element for the context variables. Gets the following templates: id, context
  • 'links' - An array of HTML links that are used for creating links to other resources. Typically this is used to create javascript links to open other sections. Link keys, are: code, context, help. See the js output format for an example.
  • 'traceLine' - Used for creating lines in the stacktrace. Gets the following template variables: reference, path, line

Alternatively if you want to use a custom callback to do all the formatting, you can use the callback key, and provide a callable:

Debugger::addFormat('custom', array('callback' => array($foo, 'outputError'));

The callback can expect two parameters. The first is an array of all the error data. The second contains the formatted strings generated using the other template strings. Keys like info, links, code, context and trace will be present depending on the other templates in the format type.

Parameters:
  • string $format required

    Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for straight HTML output, or 'txt' for unformatted text.

  • array $strings required

    Template strings, or a callback to be used for the output format.

Method defined in:
Cake/Utility/Debugger.php on line 639
Return

The resulting format string set.

_array

top

Export an array type object. Filters out keys used in datasource configuration.

The following keys are replaced with *'s

  • password
  • login
  • host
  • database
  • port
  • prefix
  • schema

Parameters:
  • array $var required

    The array to export.

  • integer $depth required

    The current depth, used for recursion tracking.

  • integer $indent required

    The current indentation level.

Method defined in:
Cake/Utility/Debugger.php on line 519
Return

string Exported array.

checkSecurityKeys

top

Verifies that the application's salt and cipher seed value has been changed from the default value.

Method defined in:
Cake/Utility/Debugger.php on line 804
Return

void

__construct

top

Constructor.

Method defined in:
Cake/Utility/Debugger.php on line 96

dump

top

Recursively formats and outputs the contents of the supplied variable.

Parameters:
  • mixed $var required

    the variable to dump

Method defined in:
Cake/Utility/Debugger.php on line 176

excerpt

top

Grabs an excerpt from a file and highlights a given line of code.

Usage:

Debugger::excerpt('/path/to/file', 100, 4);

The above would return an array of 8 items. The 4th item would be the provided line, and would be wrapped in <span class="code-highlight"></span>. All of the lines are processed with highlight_string() as well, so they have basic PHP syntax highlighting applied.

Parameters:
  • string $file required

    Absolute path to a PHP file

  • integer $line required

    Line number to highlight

  • integer $context optional 2

    Number of lines of context to extract above and below $line

Method defined in:
Cake/Utility/Debugger.php on line 396
Return

array Set of lines highlighted

See

http://php.net/highlight_string

Link
http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::excerpt

_export

top

Protected export function used to keep track of indentation and recursion.

Parameters:
  • mixed $var required

    The variable to dump.

  • integer $depth required

    The remaining depth.

  • integer $indent required

    The current indentation level.

Method defined in:
Cake/Utility/Debugger.php on line 471
Return

string The dumped variable.

exportVar

top

Converts a variable to a string for debug output.

Note: The following keys will have their contents replaced with *:

  • password
  • login
  • host
  • database
  • port
  • prefix
  • schema

This is done to protect database credentials, which could be accidentally shown in an error message if CakePHP is deployed in development mode.

Parameters:
  • string $var required

    Variable to convert

  • integer $depth optional 3

    The depth to output to. Defaults to 3.

Method defined in:
Cake/Utility/Debugger.php on line 459
Return

string Variable as a formatted string

Link
http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::exportVar

getInstance

top

Returns a reference to the Debugger singleton object instance.

Parameters:
  • string $class optional NULL

Method defined in:
Cake/Utility/Debugger.php on line 154
Return

object

getType

top

Get the type of the given variable. Will return the classname for objects.

Parameters:
  • mixed $var required

    The variable to get the type of

Method defined in:
Cake/Utility/Debugger.php on line 771
Return

string The type of variable.

_highlight

top

Wraps the highlight_string funciton in case the server API does not implement the function as it is the case of the HipHop interpreter

Parameters:
  • string $str required

    the string to convert

Method defined in:
Cake/Utility/Debugger.php on line 427
Return

string

log

top

Creates an entry in the log file. The log entry will contain a stack trace from where it was called. as well as export the variable using exportVar. By default the log is written to the debug log.

Parameters:
  • mixed $var required

    Variable or content to log

  • integer $level optional 7

    type of log to use. Defaults to LOG_DEBUG

Method defined in:
Cake/Utility/Debugger.php on line 189

_object

top

Handles object to string conversion.

Parameters:
  • string $var required

    Object to convert

  • integer $depth required

    The current depth, used for tracking recursion.

  • integer $indent required

    The current indentation level.

Method defined in:
Cake/Utility/Debugger.php on line 560
Return

string

See

Debugger::exportVar()

output

top

Switches output format, updates format strings. Can be used to switch the active output format:

Parameters:
  • string $format optional NULL

    Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for straight HTML output, or 'txt' for unformatted text.

  • array $strings optional array ( )

    Template strings to be used for the output format.

Method defined in:
Cake/Utility/Debugger.php on line 667
Return

string

Deprecated

Use Debugger::outputAs() and Debugger::addFormat(). Will be removed in 3.0

outputAs

top

Get/Set the output format for Debugger error rendering.

Parameters:
  • string $format optional NULL

    The format you want errors to be output as. Leave null to get the current format.

Method defined in:
Cake/Utility/Debugger.php on line 589
Return

mixed Returns null when setting. Returns the current format when getting.

Throws

CakeException when choosing a format that doesn't exist.

outputError

top

Takes a processed array of data from an error and displays it in the chosen format.

Parameters:
  • string $data required

Method defined in:
Cake/Utility/Debugger.php on line 694
Return

void

showError

top

Overrides PHP's default error handling.

Parameters:
  • integer $code required

    Code of error

  • string $description required

    Error description

  • string $file optional NULL

    File on which error occurred

  • integer $line optional NULL

    Line that triggered the error

  • array $context optional NULL

    Context

Method defined in:
Cake/Utility/Debugger.php on line 205
Return

boolean true if error was handled

Deprecated

This function is superseded by Debugger::outputError()

trace

top

Outputs a stack trace based on the supplied options.

Options

  • depth - The number of stack frames to return. Defaults to 999
  • format - The format you want the return. Defaults to the currently selected format. If format is 'array' or 'points' the return will be an array.
  • args - Should arguments for functions be shown? If true, the arguments for each method call will be displayed.
  • start - The stack frame to start generating a trace from. Defaults to 0

Parameters:
  • array $options optional array ( )

    Format for outputting stack trace

Method defined in:
Cake/Utility/Debugger.php on line 281

trimPath

top

Shortens file paths by replacing the application base path with 'APP', and the CakePHP core path with 'CORE'.

Parameters:
  • string $path required

    Path to shorten

Method defined in:
Cake/Utility/Debugger.php on line 358
Return

string Normalized path