/**
  * @param mixed $arg_
  */
 protected function dehydrate($arg_)
 {
     if (is_scalar($arg_)) {
         return $arg_;
     }
     if (is_array($arg_)) {
         foreach ($arg_ as &$value) {
             $value = $this->dehydrate($value);
         }
         return $arg_;
     }
     if ($arg_ instanceof \Exception) {
         return exception_as_array($arg_, true, false);
     }
     // TODO Dehydrate objects  ..
     return print_r($arg_, true);
 }
 /**
  * @see \Components\Debug_Appender::append() append
  */
 public function append($severity_, array $args_, $sourceFile_ = null, $sourceLine_ = null, $style_ = Debug::STYLE_PLAIN)
 {
     $args = [];
     foreach ($args_ as $arg) {
         if ($arg instanceof \Exception) {
             $this->m_dumps[$this->m_groupIdx][] = array_merge([$severity_, $style_], exception_as_array($arg, true, false));
         } else {
             $args[] = $this->dehydrate($arg);
         }
     }
     if (count($args)) {
         if (self::$appendDebugHeaders) {
             header('Components-Debug-' . self::$m_headerIdx++ . ':' . json_encode([$severity_, $style_, $sourceFile_, $sourceLine_, $args]));
         }
         $this->m_dumps[$this->m_groupIdx][] = [$severity_, $style_, $sourceFile_, $sourceLine_, $args];
     }
 }
/**
 * Send header containing details for given exception.
 *
 * @param \Exception $e_
 * @param integer $code_
 */
function exception_header(\Exception $e_, $code_ = 500)
{
    if ($cause = $e_->getPrevious()) {
        exception_header($cause, $code_);
    }
    $firstException = false === isset($GLOBALS['components_runtime_exception_header']);
    if ($firstException) {
        $GLOBALS['components_runtime_exception_header'] = 1;
    } else {
        $GLOBALS['components_runtime_exception_header']++;
    }
    header("Components-Exception-Count: {$GLOBALS['components_runtime_exception_header']}");
    if ($GLOBALS['components_runtime_exception_header'] > 10) {
        return;
    }
    if (false === headers_sent()) {
        $hash = \math\hasho_md5($e_);
        if (\Components\Runtime::isManagementAccess()) {
            if ($firstException) {
                header("Components-Exception-{$hash}: " . json_encode([$hash, $e_->getFile(), $e_->getLine(), exception_as_array($e_, true, false)]), true, $code_);
            } else {
                header("Components-Exception-{$hash}: " . json_encode([$hash, $e_->getFile(), $e_->getLine(), exception_as_array($e_, true, false)]));
            }
        } else {
            if ($firstException) {
                header("Components-Exception-{$hash}: {$hash}", true, $code_);
            } else {
                header("Components-Exception-{$hash}: {$hash}");
            }
        }
    }
}