/** * fb - Send messages with FireCake to FirePHP * * Much like FirePHP's fb() this method can be called with various parameter counts * fb($message) - Just send a message defaults to LOG type * fb($message, $type) - Send a message with a specific type * fb($message, $label, $type) - Send a message with a custom label and type. * * @param mixed $message Message to output. For other parameters see usage above. * @return boolean Success */ public static function fb($message) { $_this = FireCake::getInstance(); if (headers_sent($filename, $linenum)) { trigger_error(__d('debug_kit', 'Headers already sent in %s on line %s. Cannot send log data to FirePHP.', $filename, $linenum), E_USER_WARNING); return false; } if (!$_this->_enabled || !$_this->detectClientExtension()) { return false; } $args = func_get_args(); $type = $label = null; switch (count($args)) { case 1: $type = $_this->_levels['log']; break; case 2: $type = $args[1]; break; case 3: $type = $args[2]; $label = $args[1]; break; default: trigger_error(__d('debug_kit', 'Incorrect parameter count for FireCake::fb()'), E_USER_WARNING); return false; } if (isset($_this->_levels[$type])) { $type = $_this->_levels[$type]; } else { $type = $_this->_levels['log']; } $meta = array(); $skipFinalObjectEncode = false; if ($type == $_this->_levels['trace']) { $trace = debug_backtrace(); if (!$trace) { return false; } $message = FireCake::_parseTrace($trace, $args[0]); $skipFinalObjectEncode = true; } if ($_this->options['includeLineNumbers']) { if (!isset($meta['file']) || !isset($meta['line'])) { $trace = debug_backtrace(); for ($i = 0, $len = count($trace); $i < $len; $i++) { $keySet = isset($trace[$i]['class']) && isset($trace[$i]['function']); $selfCall = $keySet && strtolower($trace[$i]['class']) == 'firecake' && in_array($trace[$i]['function'], $_this->_methodIndex); if ($selfCall) { $meta['File'] = isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : ''; $meta['Line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } } } $structureIndex = 1; if ($type == $_this->_levels['dump']) { $structureIndex = 2; $_this->_sendHeader('X-Wf-1-Structure-2', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); } else { $_this->_sendHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); } $_this->_sendHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); $_this->_sendHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . $_this->_version); if ($type == $_this->_levels['groupStart']) { $meta['Collapsed'] = 'true'; } if ($type == $_this->_levels['dump']) { $dump = FireCake::jsonEncode($message); $msg = '{"' . $label . '":' . $dump . '}'; } else { $meta['Type'] = $type; if ($label !== null) { $meta['Label'] = $label; } $msg = '[' . $_this->jsonEncode($meta) . ',' . $_this->jsonEncode($message, $skipFinalObjectEncode) . ']'; } $lines = explode("\n", chunk_split($msg, 5000, "\n")); foreach ($lines as $i => $line) { if (empty($line)) { continue; } $header = 'X-Wf-1-' . $structureIndex . '-1-' . $_this->_messageIndex; if (count($lines) > 2) { $first = $i == 0 ? strlen($msg) : ''; $end = $i < count($lines) - 2 ? '\\' : ''; $message = $first . '|' . $line . '|' . $end; $_this->_sendHeader($header, $message); } else { $_this->_sendHeader($header, strlen($line) . '|' . $line . '|'); } $_this->_messageIndex++; if ($_this->_messageIndex > 99999) { trigger_error(__d('debug_kit', 'Maximum number (99,999) of messages reached!'), E_USER_WARNING); } } $_this->_sendHeader('X-Wf-1-Index', $_this->_messageIndex - 1); return true; }