🏗️ Allow access to Config from Collectors

This commit is contained in:
2021-02-22 17:43:40 +01:00
parent c8bbc35886
commit 48cc6e9f28
3 changed files with 32 additions and 7 deletions

View File

@@ -22,13 +22,13 @@ class YahooImageCollector extends Collector
*/
public function getRandomImage()
{
$word_to_search = $this->generateRandomWord();
$word_to_search = $this->getConfig()->get('collector.keywords.keywords', $this->generateRandomWord());
$client = new Client();
$crawler = $client->request('GET', sprintf(self::SEARCH_URL, $word_to_search));
$imgs = $crawler->filter('noscript img');
if ($imgs->count() < 20) {
return $this->getRandomImage();
return $this->getRandomImage(); // FIXME possible infinite loop if keywords is given
}
$img_url = $imgs->eq(random_int(0, $imgs->count() - 1))->attr('src');