Skip to content

Commit

Permalink
Move try/catch to generate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Dec 4, 2023
1 parent aa7e373 commit 9d2a791
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/Tags/Glide.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,26 @@ public function generate($items = null)
$items = is_iterable($items) ? collect($items) : collect([$items]);

return $items->map(function ($item) {
$data = ['url' => $this->generateGlideUrl($item)];
try {
$data = ['url' => $this->generateGlideUrl($item)];

if ($this->isValidExtension($item)) {
$path = $this->generateImage($item);
$attrs = Attributes::from(GlideManager::cacheDisk(), $path);
$data = array_merge($data, $attrs);
}
if ($this->isValidExtension($item)) {
$path = $this->generateImage($item);
$attrs = Attributes::from(GlideManager::cacheDisk(), $path);
$data = array_merge($data, $attrs);
}

if ($item instanceof Augmentable) {
$data = array_merge($item->toAugmentedArray(), $data);
}
if ($item instanceof Augmentable) {
$data = array_merge($item->toAugmentedArray(), $data);
}

return $data;
} catch (\Exception $e) {
\Log::error($e->getMessage());

return $data;
})->all();
return null;
}
})->filter()->all();
}

/**
Expand All @@ -156,22 +162,16 @@ public function generate($items = null)
*/
private function generateImage($item)
{
try {
$item = $this->normalizeItem($item);
$params = $this->getGlideParams($item);
$item = $this->normalizeItem($item);
$params = $this->getGlideParams($item);

if (is_string($item) && Str::isUrl($item)) {
return Str::startsWith($item, ['http://', 'https://'])
? $this->getGenerator()->generateByUrl($item, $params)
: $this->getGenerator()->generateByPath($item, $params);
}

return $this->getGenerator()->generateByAsset(Asset::find($item), $params);
} catch (\Exception $e) {
\Log::error($e->getMessage());

return null;
if (is_string($item) && Str::isUrl($item)) {
return Str::startsWith($item, ['http://', 'https://'])
? $this->getGenerator()->generateByUrl($item, $params)
: $this->getGenerator()->generateByPath($item, $params);
}

return $this->getGenerator()->generateByAsset(Asset::find($item), $params);
}

/**
Expand Down

0 comments on commit 9d2a791

Please sign in to comment.