Skip to content

Commit

Permalink
PHP 8.1 awesomeness
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Apr 26, 2024
1 parent dd0851b commit 217fe81
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Views/ViewExceptionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spatie\LaravelIgnition\Views;

use Exception;
use Illuminate\Contracts\View\Engine;
use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
Expand All @@ -19,7 +18,9 @@
class ViewExceptionMapper
{
protected Engine $compilerEngine;

protected BladeSourceMapCompiler $bladeSourceMapCompiler;

protected array $knownPaths;

public function __construct(BladeSourceMapCompiler $bladeSourceMapCompiler)
Expand Down Expand Up @@ -80,15 +81,27 @@ protected function createException(Throwable $baseException): IgnitionViewExcept

protected function modifyViewsInTrace(IgnitionViewException $exception): void
{
$viewIndex = null;


$trace = Collection::make($exception->getPrevious()->getTrace())
->map(function ($trace) {
->map(function ($trace, $index) use (&$viewIndex) {
if ($originalPath = $this->findCompiledView(Arr::get($trace, 'file', ''))) {
$trace['file'] = $originalPath;
$trace['line'] = $this->getBladeLineNumber($trace['file'], $trace['line']);

if ($viewIndex === null) {
$viewIndex = $index;
}
}

return $trace;
})->toArray();
})
->when(
$viewIndex !== null,
fn (Collection $trace) => $trace->slice($viewIndex + 1) // Remove all traces before the view
)
->toArray();

$traceProperty = new ReflectionProperty('Exception', 'trace');
$traceProperty->setAccessible(true);
Expand Down

0 comments on commit 217fe81

Please sign in to comment.