private static function send(array $output, string $ident = '') : bool
{
// Headers were already sent, can not proceed
if (headers_sent()) {
return false;
}
// Logging is disabled
if (!self::$enabled) {
return false;
}
// Sending only if FirePHP is installed
if (!self::isInstalled()) {
return false;
}
// Sent headers count
static $no = 0;
// Adding filename and line where logging was called
$first = reset($output);
if (empty($first['File'])) {
// Cut message information
$first = array_shift($output);
// Find file
$backtrace = debug_backtrace();
$hop = array_shift($backtrace);
// Remove \Jyxo\FirePhp call
while (__FILE__ === $hop['file']) {
$hop = array_shift($backtrace);
}
// Add file information
$first['File'] = $hop['file'];
$first['Line'] = $hop['line'];
// And return altered information back
array_unshift($output, $first);
}
// Splitting result
$parts = str_split(json_encode($output), 5000);
// If an identifier was provided, delete previous messages with that identifier
if (!empty($ident)) {
static $idents = [];
// Delete previous send
if (isset($idents[$ident])) {
for ($i = $idents[$ident][0]; $i <= $idents[$ident][1]; $i++) {
header_remove('X-Wf-Jyxo-1-1-Jyxo' . $i);
}
}
// Save identifiers of headers that will be actually used
$idents[$ident] = [$no + 1, $no + count($parts)];
}
// Sending
header('X-Wf-Protocol-Jyxo: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
header('X-Wf-Jyxo-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
header('X-Wf-Jyxo-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
foreach ($parts as $part) {
$no++;
header(sprintf('X-Wf-Jyxo-1-1-Jyxo%s: |%s|\\', $no, $part));
}
// Last one is sent again but without \
header(sprintf('X-Wf-Jyxo-1-1-Jyxo%s: |%s|', $no, $part));
return true;
}