Created
May 24, 2017 15:55
-
-
Save pilot/a83ed432b769d6bf4546cc1ecdd3d6d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Service; | |
use Symfony\Component\HttpFoundation\RequestStack; | |
/** | |
* Class ImagePathGenerator | |
*/ | |
class ImagePathGenerator | |
{ | |
const LOGO_PREFIX = '/store/uploads/logo/'; | |
private $host; | |
private $requestStack; | |
/** | |
* ImagePathGenerator constructor. | |
* @param string $host | |
* @param RequestStack $requestStack | |
*/ | |
public function __construct($host, RequestStack $requestStack) | |
{ | |
$this->host = $host; | |
$this->requestStack = $requestStack; | |
} | |
/** | |
* @param string $file | |
* @return array | |
*/ | |
public function generateLogoSizes($file) | |
{ | |
return $this->generateSizes(self::LOGO_PREFIX, $file); | |
} | |
/** | |
* @param string $file | |
* @return array | |
*/ | |
public function generateImagesSizes($file) | |
{ | |
return $this->generateSizes('', $file); | |
} | |
protected function generateSizes($prefix, $file) | |
{ | |
$request = $this->requestStack->getCurrentRequest(); | |
$template = $request->getScheme().'://'.$request->getHost().'/transform/resize_%sx-/%s'; | |
return [ | |
'small' => sprintf($template, 200, $this->host.$prefix.$file), | |
'medium' => sprintf($template, 500, $this->host.$prefix.$file), | |
'large' => $this->host.$prefix.$file, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment