Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Spatie\FlareClient\FlareMiddleware;
4
 
5
use ArrayObject;
6
use Closure;
7
use Spatie\FlareClient\Report;
8
 
9
class AddDocumentationLinks implements FlareMiddleware
10
{
11
    protected ArrayObject $documentationLinkResolvers;
12
 
13
    public function __construct(ArrayObject $documentationLinkResolvers)
14
    {
15
        $this->documentationLinkResolvers = $documentationLinkResolvers;
16
    }
17
 
18
    public function handle(Report $report, Closure $next)
19
    {
20
        if (! $throwable = $report->getThrowable()) {
21
            return $next($report);
22
        }
23
 
24
        $links = $this->getLinks($throwable);
25
 
26
        if (count($links)) {
27
            $report->addDocumentationLinks($links);
28
        }
29
 
30
        return $next($report);
31
    }
32
 
33
    /** @return array<int, string> */
34
    protected function getLinks(\Throwable $throwable): array
35
    {
36
        $allLinks = [];
37
 
38
        foreach ($this->documentationLinkResolvers as $resolver) {
39
            $resolvedLinks = $resolver($throwable);
40
 
41
            if (is_null($resolvedLinks)) {
42
                continue;
43
            }
44
 
45
            if (is_string($resolvedLinks)) {
46
                $resolvedLinks = [$resolvedLinks];
47
            }
48
 
49
            foreach ($resolvedLinks as $link) {
50
                $allLinks[] = $link;
51
            }
52
        }
53
 
54
        return array_values(array_unique($allLinks));
55
    }
56
}