-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Allow to set a base dir for Resizer to remove from hash #32
Changes from 1 commit
f484041
6277cc4
ae59304
8b776dd
657665b
858efa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,14 +35,20 @@ class Resizer implements ResizerInterface | |
*/ | ||
private $cacheDir; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $baseDir; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $cacheDir | ||
* @param string $baseDir | ||
* @param ResizeCalculatorInterface|null $calculator | ||
* @param Filesystem|null $filesystem | ||
*/ | ||
public function __construct($cacheDir, ResizeCalculatorInterface $calculator = null, Filesystem $filesystem = null) | ||
public function __construct($cacheDir, $baseDir = null, ResizeCalculatorInterface $calculator = null, Filesystem $filesystem = null) | ||
{ | ||
if (null === $calculator) { | ||
$calculator = new ResizeCalculator(); | ||
|
@@ -53,6 +59,7 @@ public function __construct($cacheDir, ResizeCalculatorInterface $calculator = n | |
} | ||
|
||
$this->cacheDir = (string) $cacheDir; | ||
$this->baseDir = $baseDir; | ||
$this->calculator = $calculator; | ||
$this->filesystem = $filesystem; | ||
} | ||
|
@@ -165,16 +172,21 @@ protected function createImage(ImageInterface $image, $path) | |
* @param ResizeCoordinatesInterface $coordinates | ||
* @param ResizeOptionsInterface $options | ||
* | ||
* @return string The realtive target path | ||
* @return string The relative target path | ||
*/ | ||
private function createCachePath($path, ResizeCoordinatesInterface $coordinates, ResizeOptionsInterface $options) | ||
{ | ||
$pathinfo = pathinfo($path); | ||
$imagineOptions = $options->getImagineOptions(); | ||
ksort($imagineOptions); | ||
|
||
$hashPath = $path; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is no |
||
if (null !== $this->baseDir) { | ||
$hashPath = $this->filesystem->makePathRelative($path, $this->baseDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use |
||
} | ||
|
||
$hash = substr(md5(implode('|', array_merge( | ||
[$path, filemtime($path), $coordinates->getHash()], | ||
[$hashPath, filemtime($path), $coordinates->getHash()], | ||
array_keys($imagineOptions), | ||
array_values($imagineOptions) | ||
))), 0, 9); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you not add it as last argument? Would save a lot of adjustments below.