Commit 7a0eef4e authored by Nicolas Widart's avatar Nicolas Widart

Refactor the file exists check

parent 3efc4fd1
......@@ -41,14 +41,11 @@ class Imagy
public function get($path, $thumbnail, $forceCreate = false)
{
$filename = '/assets/media/' . $this->newFilename($path, $thumbnail);
try {
$this->finder->get(public_path(). $filename);
if (!$forceCreate) {
return $filename;
}
} catch (FileNotFoundException $e) {
// Continue execution
if ($this->returnCreatedFile($filename, $forceCreate)) {
return $filename;
}
$image = $this->image->make(public_path() . $path);
foreach ($this->config->get("media::thumbnails.{$thumbnail}") as $manipulation => $options) {
......@@ -74,4 +71,15 @@ class Imagy
return $filename . '_' . $thumbnail . '.' . pathinfo($path, PATHINFO_EXTENSION);
}
/**
* Return the already created file if it exists and force create is false
* @param string $filename
* @param bool $forceCreate
* @return bool
*/
private function returnCreatedFile($filename, $forceCreate)
{
return $this->finder->isFile(public_path() . $filename) && !$forceCreate;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment