| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Spatie\LaravelIgnition\Support;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Support\Collection;
|
|
|
6 |
use Illuminate\Support\Str;
|
|
|
7 |
use Spatie\LaravelIgnition\Exceptions\ViewException;
|
|
|
8 |
use Throwable;
|
|
|
9 |
|
|
|
10 |
class LaravelDocumentationLinkFinder
|
|
|
11 |
{
|
|
|
12 |
public function findLinkForThrowable(Throwable $throwable): ?string
|
|
|
13 |
{
|
|
|
14 |
if ($throwable instanceof ViewException) {
|
|
|
15 |
$throwable = $throwable->getPrevious();
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
$majorVersion = LaravelVersion::major();
|
|
|
19 |
|
|
|
20 |
if (str_contains($throwable->getMessage(), Collection::class)) {
|
|
|
21 |
return "https://laravel.com/docs/{$majorVersion}.x/collections#available-methods";
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
$type = $this->getType($throwable);
|
|
|
25 |
|
|
|
26 |
if (! $type) {
|
|
|
27 |
return null;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
return match ($type) {
|
|
|
31 |
'Auth' => "https://laravel.com/docs/{$majorVersion}.x/authentication",
|
|
|
32 |
'Broadcasting' => "https://laravel.com/docs/{$majorVersion}.x/broadcasting",
|
|
|
33 |
'Container' => "https://laravel.com/docs/{$majorVersion}.x/container",
|
|
|
34 |
'Database' => "https://laravel.com/docs/{$majorVersion}.x/eloquent",
|
|
|
35 |
'Pagination' => "https://laravel.com/docs/{$majorVersion}.x/pagination",
|
|
|
36 |
'Queue' => "https://laravel.com/docs/{$majorVersion}.x/queues",
|
|
|
37 |
'Routing' => "https://laravel.com/docs/{$majorVersion}.x/routing",
|
|
|
38 |
'Session' => "https://laravel.com/docs/{$majorVersion}.x/session",
|
|
|
39 |
'Validation' => "https://laravel.com/docs/{$majorVersion}.x/validation",
|
|
|
40 |
'View' => "https://laravel.com/docs/{$majorVersion}.x/views",
|
|
|
41 |
default => null,
|
|
|
42 |
};
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
protected function getType(?Throwable $throwable): ?string
|
|
|
46 |
{
|
|
|
47 |
if (! $throwable) {
|
|
|
48 |
return null;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if (str_contains($throwable::class, 'Illuminate')) {
|
|
|
52 |
return Str::between($throwable::class, 'Illuminate\\', '\\');
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
if (str_contains($throwable->getMessage(), 'Illuminate')) {
|
|
|
56 |
return explode('\\', Str::between($throwable->getMessage(), 'Illuminate\\', '\\'))[0];
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
return null;
|
|
|
60 |
}
|
|
|
61 |
}
|