Provide custom logging and error handling.
Debugger overrides PHP's default error handling to provide stack traces and enhanced logging
$_data
protected array
$_defaultConfig
protected array
$_outputFormat
protected string
$_templates
protected array
Templates used when generating trace or error strings. Can be global or indexed by the format value used in $_outputFormat.
$errors
public array
Wraps the highlight_string function in case the server API does not implement the function as it is the case of the HipHop interpreter
Get the type of the given variable. Will return the class name for objects.
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.
Shortens file paths by replacing the application base path with 'APP', and the CakePHP core path with 'CORE'.
_array( array $var , integer $depth , integer $indent )
Export an array type object. Filters out keys used in datasource configuration.
The following keys are replaced with ***'s
$var
$depth
$indent
_export( mixed $var , integer $depth , integer $indent )
Protected export function used to keep track of indentation and recursion.
$var
$depth
$indent
_highlight( string $str )
Wraps the highlight_string function in case the server API does not implement the function as it is the case of the HipHop interpreter
$str
_object( object $var , integer $depth , integer $indent )
Handles object to string conversion.
$var
$depth
$indent
addFormat( string $format , array $strings )
Add an output format or update a format in Debugger.
Debugger::addFormat('custom', $data);
Where $data is an array of strings that use Text::insert() variable replacement. The template vars should be in a {:id}
style. An error formatter can have the following keys:
id
, error
, code
, description
, path
, line
, links
, info
code
, context
and trace
. Will be set with the contents of the other template keys.trace
id
, context
code
, context
, help
. See the js output format for an example.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', ['callback' => [$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.
$format
Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for straight HTML output, or 'txt' for unformatted text.
$strings
checkSecurityKeys( )
Verifies that the application's salt and cipher seed value has been changed from the default value.
configInstance( string|array|null $key null , mixed|null $value null , boolean $merge true )
Read or write configuration options for the Debugger instance.
$key
optional null $value
optional null $merge
optional true Cake\Core\Exception\Exception
dump( mixed $var , integer $depth 3 )
Recursively formats and outputs the contents of the supplied variable.
$var
$depth
optional 3 excerpt( string $file , integer $line , integer $context 2 )
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.
$file
$line
$context
optional 2 exportVar( string $var , integer $depth 3 )
Converts a variable to a string for debug output.
Note: The following keys will have their contents replaced with *****
:
This is done to protect database credentials, which could be accidentally shown in an error message if CakePHP is deployed in development mode.
$var
$depth
optional 3 formatTrace( array|Exception $backtrace , array $options [] )
Formats a stack trace based on the supplied options.
depth
- The number of stack frames to return. Defaults to 999format
- 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$backtrace
$options
optional [] getInstance( string|null $class null )
Returns a reference to the Debugger singleton object instance.
$class
optional null Cake\Error\Debugger
getType( mixed $var )
Get the type of the given variable. Will return the class name for objects.
$var
log( mixed $var , integer|string $level 'debug' , integer $depth 3 )
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.
$var
$level
optional 'debug' $depth
optional 3 outputAs( string|null $format null )
Get/Set the output format for Debugger error rendering.
$format
optional null The format you want errors to be output as. Leave null to get the current format.
outputError( string $data )
Takes a processed array of data from an error and displays it in the chosen format.
$data
printVar( mixed $var , array $location [] , boolean|null $showHtml null )
Prints out debug information about given variable.
$var
$location
optional [] If contains keys "file" and "line" their values will be used to show location info.
$showHtml
optional null If set to true, the method prints the debug data in a browser-friendly way.
setOutputMask( array $value , boolean $merge true )
Sets configurable masking of debugger output by property name and array key names.
Debugger::setOutputMask(['password' => '[*************]');
$value
$merge
optional true trace( array $options [] )
Outputs a stack trace based on the supplied options.
depth
- The number of stack frames to return. Defaults to 999format
- 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$options
optional [] trimPath( string $path )
Shortens file paths by replacing the application base path with 'APP', and the CakePHP core path with 'CORE'.
$path
_configDelete( string $key )
Deletes a single config key.
$key
Cake\Core\Exception\Exception
_configRead( string|null $key )
Reads a config key.
$key
_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Writes a config key.
$key
$value
$merge
optional false True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Cake\Core\Exception\Exception
config( string|array|null $key null , mixed|null $value null , boolean $merge true )
Gets/Sets the config.
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key');
Reading a nested value:
$this->config('some.nested.key');
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
optional null $value
optional null $merge
optional true Cake\Core\Exception\Exception
configShallow( string|array $key , mixed|null $value null )
Merge provided config with existing config. Unlike config()
which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key
$value
optional null getConfig( string|null $key null )
Returns the config.
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key');
Reading a nested value:
$this->getConfig('some.nested.key');
$key
optional null setConfig( string|array $key , mixed|null $value null , boolean $merge true )
Sets the config.
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
$key
$value
optional null $merge
optional true Cake\Core\Exception\Exception
protected array
Templates used when generating trace or error strings. Can be global or indexed by the format value used in $_outputFormat.
[ 'log' => [ 'trace' => '{:reference} - {:path}, line {:line}', 'error' => "{:error} ({:code}): {:description} in [{:file}, line {:line}]" ], 'js' => [ 'error' => '', 'info' => '', 'trace' => '<pre class="stack-trace">{:trace}</pre>', 'code' => '', 'context' => '', 'links' => [], 'escapeContext' => true, ], 'html' => [ 'trace' => '<pre class="cake-error trace"><b>Trace</b> <p>{:trace}</p></pre>', 'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>', 'escapeContext' => true, ], 'txt' => [ 'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}", 'code' => '', 'info' => '' ], 'base' => [ 'traceLine' => '{:reference} - {:path}, line {:line}', 'trace' => "Trace:\n{:trace}\n", 'context' => "Context:\n{:context}\n", ] ]
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Error.Debugger.html