1 | <?php |
||
14 | class Crawler implements \Countable |
||
15 | { |
||
16 | private $httpClient; |
||
17 | private $messageFactory; |
||
18 | private $logger; |
||
19 | private $urlProviders; |
||
20 | |||
21 | /** |
||
22 | * @param HttpClient $httpClient |
||
23 | * @param MessageFactory $messageFactory |
||
24 | * @param LoggerInterface $logger |
||
25 | * @param UrlProvider[] $urlProviders |
||
26 | */ |
||
27 | 6 | public function __construct(HttpClient $httpClient, MessageFactory $messageFactory, LoggerInterface $logger = null, array $urlProviders = []) |
|
28 | { |
||
29 | 6 | $this->httpClient = $httpClient; |
|
30 | 6 | $this->messageFactory = $messageFactory; |
|
31 | 6 | $this->logger = $logger; |
|
32 | 6 | $this->urlProviders = $urlProviders; |
|
33 | 3 | } |
|
34 | |||
35 | /** |
||
36 | * @param UrlProvider $provider |
||
37 | */ |
||
38 | 2 | public function addUrlProvider(UrlProvider $provider) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 4 | public function count() |
|
56 | |||
57 | /** |
||
58 | * @param callable $callback Response as first argument, calling URL as second |
||
59 | */ |
||
60 | 4 | public function crawl(callable $callback = null) |
|
72 | |||
73 | /** |
||
74 | * @param ResponseInterface $response |
||
75 | * @param string $url |
||
76 | */ |
||
77 | 2 | private function log(ResponseInterface $response, $url) |
|
87 | |||
88 | /** |
||
89 | * @return array |
||
90 | */ |
||
91 | 4 | private function getUrls() |
|
101 | } |
||
102 |