$errors
$errors : array
A list of errors generated by the application.
Provide custom logging and error handling.
Debugger overrides PHP's default error handling to provide stack traces and enhanced logging
setConfig(string|array $key, mixed|null $value = null, boolean $merge = true) : $this
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']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
getConfig(string|null $key = null, mixed $default = null) : mixed
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');
Reading with default value:
$this->getConfig('some-key', 'default-value');
string|null | $key | The key to get or null for the whole config. |
mixed | $default | The return value when the key does not exist. |
Config value being read.
config(string|array|null $key = null, mixed|null $value = null, boolean $merge = true) : mixed
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']);
string|array|null | $key | The key to get/set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
Config value being read, or the object itself on write operations.
configShallow(string|array $key, mixed|null $value = null) : $this
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->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
None found |
None found |
getInstance(string|null $class = null) : \Cake\Error\Debugger
Returns a reference to the Debugger singleton object instance.
string|null | $class | Class name. |
None found |
configInstance(string|array|null $key = null, mixed|null $value = null, boolean $merge = true) : mixed
Read or write configuration options for the Debugger instance.
string|array|null | $key | The key to get/set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
Config value being read, or the object itself on write operations.
None found |
None found |
setOutputMask(array $value, boolean $merge = true) : void
Sets configurable masking of debugger output by property name and array key names.
Debugger::setOutputMask(['password' => '[*****]');
array | $value | An array where keys are replaced by their values in output. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
None found |
dump(mixed $var, integer $depth = 3) : void
Recursively formats and outputs the contents of the supplied variable.
mixed | $var | The variable to dump. |
integer | $depth | The depth to output to. Defaults to 3. |
None found |
log(mixed $var, integer|string $level = 'debug', integer $depth = 3) : void
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.
mixed | $var | Variable or content to log. |
integer|string | $level | Type of log to use. Defaults to 'debug'. |
integer | $depth | The depth to output to. Defaults to 3. |
None found |
trace(array $options = array()) : mixed
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 0array | $options | Format for outputting stack trace. |
Formatted stack trace.
None found |
formatTrace(array|\Exception $backtrace, array $options = array()) : mixed
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 0array|\Exception | $backtrace | Trace as array or an exception object. |
array | $options | Format for outputting stack trace. |
Formatted stack trace.
None found |
trimPath(string $path) : string
Shortens file paths by replacing the application base path with 'APP', and the CakePHP core path with 'CORE'.
string | $path | Path to shorten. |
Normalized path
None found |
excerpt(string $file, integer $line, integer $context = 2) : array
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.
string | $file | Absolute path to a PHP file. |
integer | $line | Line number to highlight. |
integer | $context | Number of lines of context to extract above and below $line. |
Set of lines highlighted
None found |
exportVar(mixed $var, integer $depth = 3) : string
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.
mixed | $var | Variable to convert. |
integer | $depth | The depth to output to. Defaults to 3. |
Variable as a formatted string
None found |
getOutputFormat() : string
Get the output format for Debugger error rendering.
Returns the current format when getting.
None found |
setOutputFormat(string $format) : void
Set the output format for Debugger error rendering.
string | $format | The format you want errors to be output as. |
When choosing a format that doesn't exist.
None found |
outputAs(string|null $format = null) : string|null
Get/Set the output format for Debugger error rendering.
string|null | $format | The format you want errors to be output as. Leave null to get the current format. |
When choosing a format that doesn't exist.
Returns null when setting. Returns the current format when getting.
None found |
addFormat(string $format, array $strings) : array
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.
string | $format | Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for straight HTML output, or 'txt' for unformatted text. |
array | $strings | Template strings, or a callback to be used for the output format. |
The resulting format string set.
None found |
outputError(array $data) : void
Takes a processed array of data from an error and displays it in the chosen format.
array | $data | Data to output. |
None found |
getType(mixed $var) : string
Get the type of the given variable. Will return the class name for objects.
mixed | $var | The variable to get the type of. |
The type of variable.
None found |
printVar(mixed $var, array $location = array(), boolean|null $showHtml = null) : void
Prints out debug information about given variable.
mixed | $var | Variable to show debug information for. |
array | $location | If contains keys "file" and "line" their values will be used to show location info. |
boolean|null | $showHtml | If set to true, the method prints the debug data in a browser-friendly way. |
None found |
checkSecurityKeys() : void
Verifies that the application's salt and cipher seed value has been changed from the default value.
None found |
_configRead(string|null $key) : mixed
Reads a config key.
string|null | $key | Key to read. |
None found |
_configWrite(string|array $key, mixed $value, boolean|string $merge = false) : void
Writes a config key.
string|array | $key | Key to write to. |
mixed | $value | Value to write. |
boolean|string | $merge | True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false. |
if attempting to clobber existing config
None found |
_configDelete(string $key) : void
Deletes a single config key.
string | $key | Key to delete. |
if attempting to clobber existing config
None found |
_highlight(string $str) : string
Wraps the highlight_string function in case the server API does not implement the function as it is the case of the HipHop interpreter
string | $str | The string to convert. |
None found |
_export(mixed $var, integer $depth, integer $indent) : string
Protected export function used to keep track of indentation and recursion.
mixed | $var | The variable to dump. |
integer | $depth | The remaining depth. |
integer | $indent | The current indentation level. |
The dumped variable.
None found |
_array(array $var, integer $depth, integer $indent) : string
Export an array type object. Filters out keys used in datasource configuration.
The following keys are replaced with ***'s
array | $var | The array to export. |
integer | $depth | The current depth, used for recursion tracking. |
integer | $indent | The current indentation level. |
Exported array.
None found |
_object(object $var, integer $depth, integer $indent) : string
Handles object to string conversion.
object | $var | Object to convert. |
integer | $depth | The current depth, used for tracking recursion. |
integer | $indent | The current indentation level. |
None found |