Файл: vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Renderer/Renderer.php
Строк: 164
<?php
namespace IlluminateFoundationExceptionsRenderer;
use IlluminateContractsViewFactory;
use IlluminateFoundationExceptionsRendererMappersBladeMapper;
use IlluminateHttpRequest;
use SymfonyComponentErrorHandlerErrorRendererHtmlErrorRenderer;
use Throwable;
class Renderer
{
/**
* The path to the renderer's distribution files.
*
* @var string
*/
protected const DIST = __DIR__.'/../../resources/exceptions/renderer/dist/';
/**
* The view factory instance.
*
* @var IlluminateContractsViewFactory
*/
protected $viewFactory;
/**
* The exception listener instance.
*
* @var IlluminateFoundationExceptionsRendererListener
*/
protected $listener;
/**
* The HTML error renderer instance.
*
* @var SymfonyComponentErrorHandlerErrorRendererHtmlErrorRenderer
*/
protected $htmlErrorRenderer;
/**
* The Blade mapper instance.
*
* @var IlluminateFoundationExceptionsRendererMappersBladeMapper
*/
protected $bladeMapper;
/**
* The application's base path.
*
* @var string
*/
protected $basePath;
/**
* Creates a new exception renderer instance.
*
* @param IlluminateContractsViewFactory $viewFactory
* @param IlluminateFoundationExceptionsRendererListener $listener
* @param SymfonyComponentErrorHandlerErrorRendererHtmlErrorRenderer $htmlErrorRenderer
* @param IlluminateFoundationExceptionsRendererMappersBladeMapper $bladeMapper
* @param string $basePath
*/
public function __construct(
Factory $viewFactory,
Listener $listener,
HtmlErrorRenderer $htmlErrorRenderer,
BladeMapper $bladeMapper,
string $basePath,
) {
$this->viewFactory = $viewFactory;
$this->listener = $listener;
$this->htmlErrorRenderer = $htmlErrorRenderer;
$this->bladeMapper = $bladeMapper;
$this->basePath = $basePath;
}
/**
* Render the given exception as an HTML string.
*
* @param IlluminateHttpRequest $request
* @param Throwable $throwable
* @return string
*/
public function render(Request $request, Throwable $throwable)
{
$flattenException = $this->bladeMapper->map(
$this->htmlErrorRenderer->render($throwable),
);
$exception = new Exception($flattenException, $request, $this->listener, $this->basePath);
$exceptionAsMarkdown = $this->viewFactory->make('laravel-exceptions-renderer::markdown', [
'exception' => $exception,
])->render();
return $this->viewFactory->make('laravel-exceptions-renderer::show', [
'exception' => $exception,
'exceptionAsMarkdown' => $exceptionAsMarkdown,
])->render();
}
/**
* Get the renderer's CSS content.
*
* @return string
*/
public static function css()
{
return '<style>'.file_get_contents(static::DIST.'styles.css').'</style>';
}
/**
* Get the renderer's JavaScript content.
*
* @return string
*/
public static function js()
{
$viteJsAutoRefresh = '';
$vite = app(IlluminateFoundationVite::class);
if (is_file($vite->hotFile())) {
$viteJsAutoRefresh = $vite->__invoke([]);
}
return '<script>'
.file_get_contents(static::DIST.'scripts.js')
.'</script>'.$viteJsAutoRefresh;
}
}