private function getCoverFileUnderSameDirectory()
{
// As directory scanning can be expensive, we cache and reuse the result.
$cacheKey = md5($this->path . '_cover');
if (!is_null($cover = Cache::get($cacheKey))) {
return $cover;
}
$matches = array_keys(iterator_to_array(Finder::create()->depth(0)->ignoreUnreadableDirs()->files()->followLinks()->name('/(cov|fold)er\\.(jpe?g|png)$/i')->in(dirname($this->path))));
$cover = $matches ? $matches[0] : false;
// Even if a file is found, make sure it's a real image.
if ($cover && exif_imagetype($cover) === false) {
$cover = false;
}
Cache::put($cacheKey, $cover, 24 * 60);
return $cover;
}