CoreFiles by mySites.guru
CliRenderer.php67 lines, 1,494 bytes, from Joomla_4.2.0-Stable-Full_Package.zip
Raw History Compare with 4.1.5
md5
22679dd1daaa692a552fc52897a60394
sha1
6b1b40c97ac76d90696b4954dfc8740f50e9462b
sha256
0c2c41bdd0b4efc4350c549d9f0488123c1d184172345b2651de5a22a2a3c070
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Error\Renderer;

use Joomla\CMS\Error\AbstractRenderer;

/**
 * Cli error renderer
 *
 * @since  4.0.0
 */
class CliRenderer extends AbstractRenderer
{
    /**
     * The format (type)
     *
     * @var    string
     * @since  4.0.0
     */
    protected $type = 'cli';

    /**
     * Render the error for the given object.
     *
     * @param   \Throwable  $error  The error object to be rendered
     *
     * @return  string
     *
     * @since   4.0.0
     */
    public function render(\Throwable $error): string
    {
        $buffer = PHP_EOL . 'Error occurred: ' . $error->getMessage() . PHP_EOL . $this->getTrace($error);

        if ($prev = $error->getPrevious()) {
            $buffer .= PHP_EOL . PHP_EOL . 'Previous Exception: ' . $prev->getMessage() . PHP_EOL . $this->getTrace($prev);
        }

        return $buffer;
    }

    /**
     * Returns a trace for the given error.
     *
     * @param   \Throwable  $error  The error
     *
     * @return  string
     *
     * @since   4.0.0
     */
    private function getTrace(\Throwable $error): string
    {
        // Include the stack trace only if in debug mode
        if (!JDEBUG) {
            return '';
        }

        return PHP_EOL . $error->getTraceAsString() . PHP_EOL;
    }
}

The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.