From bea673807c6ff92f62ce4b2991599c4db8eeeec3 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 6 Feb 2021 11:57:25 +0000 Subject: [PATCH] add method to setCrawlProfile, add type hinting --- src/Crawler.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Crawler.php b/src/Crawler.php index e2a4a13..8592ded 100644 --- a/src/Crawler.php +++ b/src/Crawler.php @@ -10,13 +10,14 @@ use Psr\Http\Message\UriInterface; use Spatie\Crawler\Crawler as SpatieCrawler; use Spatie\Crawler\CrawlUrl; use Spatie\Crawler\CrawlAllUrls; +use Spatie\Crawler\CrawlProfile; class Crawler{ private $observer; private $crawler; - public function __construct($reqOps=[]){ + public function __construct(array $reqOps=[]){ $this->crawler = SpatieCrawler::create(array_merge($reqOps, [ RequestOptions::ALLOW_REDIRECTS => [ 'track_redirects' => true, @@ -28,15 +29,21 @@ class Crawler{ $this->crawler->setCrawlProfile(new CrawlAllUrls()); } - public function setUserAgent($agent){ + public function setUserAgent(String $agent) : self{ $this->crawler->setUserAgent($agent); + return $this; } - public function crawl($url){ + public function setCrawlProfile(CrawlProfile $p) : self{ + $this->crawler->setCrawlProfile($p); + return $this; + } + + public function crawl(String $url) : void{ $this->crawler->startCrawling($url); } - public function getResults(){ + public function getResults() : array{ return $this->observer->results; }