/** * 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: * * - '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', ['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. * * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for * straight HTML output, or 'txt' for unformatted text. * @param array $strings Template strings, or a callback to be used for the output format. * @return array The resulting format string set. */ public static function addFormat($format, array $strings) { $self = Debugger::getInstance(); if (isset($self->_templates[$format])) { if (isset($strings['links'])) { $self->_templates[$format]['links'] = array_merge($self->_templates[$format]['links'], $strings['links']); unset($strings['links']); } $self->_templates[$format] = $strings + $self->_templates[$format]; } else { $self->_templates[$format] = $strings; } return $self->_templates[$format]; }
/** * test getInstance. * * @return void */ public function testGetInstance() { $result = Debugger::getInstance(); $this->assertInstanceOf('Cake\\Error\\Debugger', $result); $result = Debugger::getInstance(__NAMESPACE__ . '\\DebuggerTestCaseDebugger'); $this->assertInstanceOf(__NAMESPACE__ . '\\DebuggerTestCaseDebugger', $result); $result = Debugger::getInstance(); $this->assertInstanceOf(__NAMESPACE__ . '\\DebuggerTestCaseDebugger', $result); $result = Debugger::getInstance('Cake\\Error\\Debugger'); $this->assertInstanceOf('Cake\\Error\\Debugger', $result); }
/** * Display an error. * * Template method of BaseErrorHandler. * * Only when debug > 2 will a formatted error be displayed. * * @param array $error An array of error data. * @param bool $debug Whether or not the app is in debug mode. * @return void */ protected function _displayError($error, $debug) { if (!$debug) { return; } Debugger::getInstance()->outputError($error); }
/** * Switches output format, updates format strings. * Can be used to switch the active output format: * * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for * straight HTML output, or 'txt' for unformatted text. * @param array $strings Template strings to be used for the output format. * @return string * @deprecated 3.0.0 Use Debugger::outputAs() and Debugger::addFormat(). Will be removed * in 3.0 */ public static function output($format = null, $strings = array()) { $self = Debugger::getInstance(); $data = null; if ($format === null) { return Debugger::outputAs(); } if (!empty($strings)) { return Debugger::addFormat($format, $strings); } if ($format === true && !empty($self->_data)) { $data = $self->_data; $self->_data = array(); $format = false; } Debugger::outputAs($format); return $data; }