From 7d5f858ed74e19628c7375872fa41186415e27ca Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 6 Sep 2021 14:01:13 +0200 Subject: [PATCH] Return null in TagGenerator --- classes/TagGenerator.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/classes/TagGenerator.php b/classes/TagGenerator.php index 6a6f206..b4b7091 100644 --- a/classes/TagGenerator.php +++ b/classes/TagGenerator.php @@ -22,12 +22,6 @@ class TagGenerator { ksort($this->breakpoints); } - public function cacheOutput() { - return Cache::rememberForever('responsive-image-'.$this->attachment->id, function() { - return $this->output(); - }).' '.$this->attrs; - } - public function size(string $name): array { $size = collect(Setting::get('sizes'))->filter(fn ($size) => $size['name'] === $name) @@ -36,10 +30,10 @@ class TagGenerator { return explode('x', $size['aspect_ratio']); } - public function possibleFiles(string $ratio): Collection + public function possibleFiles(string $ratio): ?Collection { if (Storage::mimeType(app(FileObserver::class)->fullMediaPath($this->path)) !== 'image/jpeg') { - return collect([]); + return null; } $filename = pathinfo($this->path, PATHINFO_FILENAME); @@ -69,7 +63,9 @@ class TagGenerator { ])); } - return $result->sortBy('width'); + return $result->count() + ? $result->sortBy('width') + : null; } public function generate(string $path, ?string $ratio = 'original'): string @@ -77,7 +73,7 @@ class TagGenerator { $this->path = $path; $files = $this->possibleFiles($ratio); - if ($files->isEmpty()) { + if ($files === null) { return 'src="'.$this->media->findFiles($path)[0]->publicUrl.'"'; }