Skip to content

Commit

Permalink
Update Crawler to 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 2, 2018
1 parent 5d7abd0 commit b7bd87f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
40 changes: 30 additions & 10 deletions src/Crawler/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Crawler/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/CustomCrawlProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b7bd87f

Please sign in to comment.