Skip to content

Commit

Permalink
Merge pull request #1 from UgoSansH/fix/image-url-unique
Browse files Browse the repository at this point in the history
Patch from url image already use
  • Loading branch information
Ugo Sans H committed Mar 4, 2015
2 parents 19f9afc + d267b45 commit b9557ed
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/Ugosansh/Component/Image/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,36 @@ public function createDirectory($directory, $chmod = null, $recurisve = true)
*
* @return string
*/
public function definePath($id, $title, $extension, $prefix = '')
public function definePath($id, $title, $extension, $prefix = '', $suffix = '')
{
return sprintf(
'%s/%s-%s%s.%s',
$this->getCurrentDirectory(),
(new \DateTime())->format('His'),
$prefix,
Canonicalizer::slug($title),
$extension
);
$path = '';

if ($suffix) {
$path = sprintf(
'%s/%s-%s%s-%s.%s',
$this->getCurrentDirectory(),
(new \DateTime())->format('His'),
$prefix,
Canonicalizer::slug($title),
$suffix,
$extension
);
} else {
$path = sprintf(
'%s/%s-%s%s.%s',
$this->getCurrentDirectory(),
(new \DateTime())->format('His'),
$prefix,
Canonicalizer::slug($title),
$extension
);
}

if (file_exists(sprintf('%s/%s', $this->rootDir, $path))) {
return $this->definePath($id, $title, $extension, $prefix, intval($suffix) + 1);
}

return $path;
}

/**
Expand Down Expand Up @@ -158,4 +178,4 @@ public function getImageSource(ImageInterface $image)
return file_get_contents($path);
}

}
}

0 comments on commit b9557ed

Please sign in to comment.