Return null in TagGenerator

This commit is contained in:
Philipp Lang 2021-09-06 14:01:13 +02:00
parent 73e6e15e24
commit 7d5f858ed7
1 changed files with 6 additions and 10 deletions

View File

@ -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.'"';
}