$line) { $output .= ($offset == $errline) ? "* " : " "; $output .= str_pad("$offset:", 5); $output .= wordwrap($line ?? '', self::config()->columns ?? 0, "\n "); } $output .= "\n"; return $output; } /** * Write a backtrace * * @param array $trace * @return string */ public function renderTrace($trace = null) { $output = "Trace\n=====\n"; $output .= Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true); return $output; } public function renderParagraph($text) { return wordwrap($text ?? '', self::config()->columns ?? 0) . "\n\n"; } /** * Render the information header for the view * * @param string $title * @param string $subtitle * @param string $description * @return string */ public function renderInfo($title, $subtitle, $description = null) { $output = wordwrap(strtoupper($title ?? ''), self::config()->columns ?? 0) . "\n"; $output .= wordwrap($subtitle ?? '', self::config()->columns ?? 0) . "\n"; $output .= str_repeat('-', min(self::config()->columns, max(strlen($title ?? ''), strlen($subtitle ?? ''))) ?? 0) . "\n"; $output .= wordwrap($description ?? '', self::config()->columns ?? 0) . "\n\n"; return $output; } public function renderVariable($val, $caller) { $output = PHP_EOL; $output .= CLI::text(str_repeat('=', self::config()->columns ?? 0), 'green'); $output .= PHP_EOL; $output .= CLI::text($this->formatCaller($caller), 'blue', null, true); $output .= PHP_EOL . PHP_EOL; if (is_string($val)) { $output .= wordwrap($val ?? '', self::config()->columns ?? 0); } else { $output .= var_export($val, true); } $output .= PHP_EOL; $output .= CLI::text(str_repeat('=', self::config()->columns ?? 0), 'green'); $output .= PHP_EOL; return $output; } /** * Similar to renderVariable() but respects debug() method on object if available * * @param mixed $val * @param array $caller * @param bool $showHeader * @return string */ public function debugVariable($val, $caller, $showHeader = true) { $text = $this->debugVariableText($val); if ($showHeader) { $callerFormatted = $this->formatCaller($caller); return "Debug ($callerFormatted)\n{$text}\n\n"; } else { return $text; } } /** * Get debug text for this object * * @param mixed $val * @return string */ public function debugVariableText($val) { // Check debug if (is_object($val) && ClassInfo::hasMethod($val, 'debug')) { return $val->debug(); } // Format as array if (is_array($val)) { $result = ''; foreach ($val as $key => $valItem) { $valText = $this->debugVariableText($valItem); $result .= "$key = $valText\n"; } return $result; } // Format object if (is_object($val)) { return print_r($val, true); } // Format bool if (is_bool($val)) { return '(bool) ' . ($val ? 'true' : 'false'); } // Format text if (is_string($val)) { return wordwrap($val ?? '', self::config()->columns ?? 0); } // Other return var_export($val, true); } public function renderMessage($message, $caller, $showHeader = true) { $header = ''; if ($showHeader) { $file = basename($caller['file'] ?? ''); $line = $caller['line']; $header .= "Debug (line {$line} of {$file}):\n"; } return $header . "{$message}\n\n"; } }