| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Spatie\Sitemap\Crawler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use GuzzleHttp\Exception\RequestException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Psr\Http\Message\ResponseInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Spatie\Crawler\CrawlObserver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Psr\Http\Message\UriInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Observer extends CrawlObserver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** @var callable */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $hasCrawled; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function __construct(callable $hasCrawled) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->hasCrawled = $hasCrawled; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Called when the crawler will crawl the url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param \Psr\Http\Message\UriInterface $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function willCrawl(UriInterface $url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Called when the crawl has ended. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function finishedCrawling() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Called when the crawler has crawled the given url successfully. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param \Psr\Http\Message\UriInterface      $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param \Psr\Http\Message\ResponseInterface $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param \Psr\Http\Message\UriInterface|null $foundOnUrl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function crawled( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         UriInterface $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ResponseInterface $response, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ?UriInterface $foundOnUrl = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         ($this->hasCrawled)($url, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * Called when the crawler had a problem crawling the given url. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param \Psr\Http\Message\UriInterface         $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param \GuzzleHttp\Exception\RequestException $requestException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param \Psr\Http\Message\UriInterface|null    $foundOnUrl | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |     public function crawlFailed( | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         UriInterface $url, | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |         RequestException $requestException, | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         ?UriInterface $foundOnUrl = null | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |     ) { | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         return; | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |