1 | <?php |
||
8 | class LogBrokenLinks extends BaseReporter |
||
9 | { |
||
10 | /** |
||
11 | * @var \Illuminate\Contracts\Logging\Log |
||
12 | */ |
||
13 | protected $log; |
||
14 | |||
15 | /** |
||
16 | * @param \Illuminate\Contracts\Logging\Log $log |
||
17 | */ |
||
18 | public function __construct(Log $log) |
||
22 | |||
23 | /** |
||
24 | * Called when the crawler has crawled the given url. |
||
25 | * |
||
26 | * @param \Spatie\Crawler\Url $url |
||
27 | * @param \Psr\Http\Message\ResponseInterface|null $response |
||
28 | * @param \Spatie\Crawler\Url $foundOnUrl |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | public function hasBeenCrawled(Url $url, $response, Url $foundOnUrl = null) |
||
33 | { |
||
34 | $statusCode = parent::hasBeenCrawled($url, $response); |
||
35 | |||
36 | if ($this->isSuccessOrRedirect($statusCode) || $this->excludeStatusCode($statusCode)) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | $reason = $response ? $response->getReasonPhrase() : ''; |
||
41 | |||
42 | $logMessage = "{$statusCode} {$reason} - {$url}"; |
||
43 | |||
44 | if ($foundOnUrl) { |
||
45 | $logMessage .= " (found on {$foundOnUrl}"; |
||
46 | } |
||
47 | |||
48 | $this->log->warning($logMessage); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Called when the crawl has ended. |
||
53 | */ |
||
54 | public function finishedCrawling() |
||
76 | } |
||
77 |