diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d7f3e8..2dcb05f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ All notable changes to `laravel-sitemap` will be documented in this file -## 4.0.0 - 2018-08-02 +## 5.0.0 - 2018-03-02 + +- Update to Crawler 4.0 + +## 4.0.0 - 2018-02-08 - Update to Laravel 5.6 - Update to phpunit 7 diff --git a/README.md b/README.md index bdae9da..428b43c 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ You can create a custom crawl profile by implementing the `Spatie\Crawler\CrawlP use Spatie\Crawler\Url; use Spatie\Crawler\CrawlProfile; -class CustomCrawlProfile implements CrawlProfile +class CustomCrawlProfile extends CrawlProfile { /** * Determine if the given url should be crawled. diff --git a/UPGRADING.md b/UPGRADING.md index 1b5112f..cc6f321 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -2,6 +2,10 @@ Because there are many breaking changes an upgrade is not that easy. There are many edge cases this guide does not cover. We accept PRs to improve this guide. +## From 4.0 to 5.0 + +- `spatie/crawler` is updated to `^4.0`. This version made changes to the way custom `Profiles` and `Observers` are made. Please see the [UPGRADING](https://github.com/spatie/crawler/blob/master/UPGRADING.md) guide of `spatie/crawler` to know how to update any custom crawl profiles or observers - if you have any. + ## From 3.0 to 4.0 - `spatie/crawler` is updated to `^3.0`. This version introduced the use of PSR-7 `UriInterface` instead of a custom `Url` class. Please see the [UPGRADING](https://github.com/spatie/crawler/blob/master/UPGRADING.md) guide of `spatie/crawler` to know how to update any custom crawl profiles - if you have any. diff --git a/composer.json b/composer.json index 10f4c6d..b84a667 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": "^7.1", "illuminate/support": "~5.5.0|~5.6.0", "nesbot/carbon": "^1.21", - "spatie/crawler": "^3.0", + "spatie/crawler": "^4.0", "spatie/temporary-directory": "^1.1" }, "require-dev": { diff --git a/src/Crawler/Observer.php b/src/Crawler/Observer.php index bfac41c..6e40012 100644 --- a/src/Crawler/Observer.php +++ b/src/Crawler/Observer.php @@ -2,10 +2,12 @@ namespace Spatie\Sitemap\Crawler; +use GuzzleHttp\Exception\RequestException; +use Psr\Http\Message\ResponseInterface; use Spatie\Crawler\CrawlObserver; use Psr\Http\Message\UriInterface; -class Observer implements CrawlObserver +class Observer extends CrawlObserver { /** @var callable */ protected $hasCrawled; @@ -25,21 +27,39 @@ public function willCrawl(UriInterface $url) } /** - * Called when the crawler has crawled the given url. - * - * @param \Psr\Http\Message\UriInterface $url - * @param \Psr\Http\Message\ResponseInterface|null $response - * @param \Psr\Http\Message\UriInterface $foundOnUrl + * Called when the crawl has ended. */ - public function hasBeenCrawled(UriInterface $url, $response, ?UriInterface $foundOnUrl = null) + public function finishedCrawling() { + } + + /** + * Called when the crawler has crawled the given url successfully. + * + * @param \Psr\Http\Message\UriInterface $url + * @param \Psr\Http\Message\ResponseInterface $response + * @param \Psr\Http\Message\UriInterface|null $foundOnUrl + */ + public function crawled( + UriInterface $url, + ResponseInterface $response, + ?UriInterface $foundOnUrl = null + ) { ($this->hasCrawled)($url, $response); } /** - * Called when the crawl has ended. + * Called when the crawler had a problem crawling the given url. + * + * @param \Psr\Http\Message\UriInterface $url + * @param \GuzzleHttp\Exception\RequestException $requestException + * @param \Psr\Http\Message\UriInterface|null $foundOnUrl */ - public function finishedCrawling() - { + public function crawlFailed( + UriInterface $url, + RequestException $requestException, + ?UriInterface $foundOnUrl = null + ) { + return; } } diff --git a/src/Crawler/Profile.php b/src/Crawler/Profile.php index 31b5cef..ff041bc 100644 --- a/src/Crawler/Profile.php +++ b/src/Crawler/Profile.php @@ -5,7 +5,7 @@ use Spatie\Crawler\CrawlProfile; use Psr\Http\Message\UriInterface; -class Profile implements CrawlProfile +class Profile extends CrawlProfile { /** @var callable */ protected $profile; diff --git a/tests/CustomCrawlProfile.php b/tests/CustomCrawlProfile.php index fe659ef..333399b 100644 --- a/tests/CustomCrawlProfile.php +++ b/tests/CustomCrawlProfile.php @@ -5,7 +5,7 @@ use Spatie\Crawler\CrawlProfile; use Psr\Http\Message\UriInterface; -class CustomCrawlProfile implements CrawlProfile +class CustomCrawlProfile extends CrawlProfile { /** * Determine if the given url should be crawled.