Skip to content
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

Merged
merged 6 commits into from Mar 22, 2017
Merged

[RFC] Allow to set a base dir for Resizer to remove from hash #32

merged 6 commits into from Mar 22, 2017

Conversation

aschempp
Copy link
Member

@aschempp aschempp commented Feb 2, 2017

The resizer service can then be configured with %kernel.root_dir%/.. or with %contao.root_dir% in Contao 4.4.

ATTENTION: this is an API change and should result in v0.4

TODO:

  • do we need realpath() to convert %kernel.root_dir%/..?
  • Add unit tests

src/Resizer.php Outdated
* @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)
Copy link
Member

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.

src/Resizer.php Outdated
*/
private function createCachePath($path, ResizeCoordinatesInterface $coordinates, ResizeOptionsInterface $options)
{
$pathinfo = pathinfo($path);
$imagineOptions = $options->getImagineOptions();
ksort($imagineOptions);

$hashPath = $path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be $relPath.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no $baseDir the path would not be relative, wouldn’t $relPath be misleading then?

src/Resizer.php Outdated
*/
private function createCachePath($path, ResizeCoordinatesInterface $coordinates, ResizeOptionsInterface $options)
{
$pathinfo = pathinfo($path);
$imagineOptions = $options->getImagineOptions();
ksort($imagineOptions);

$hashPath = $path;
if (null !== $this->baseDir) {
$hashPath = $this->filesystem->makePathRelative($path, $this->baseDir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use Webmozart\PathUtil\Path here instead. As in src/Image.php:108

@ausi
Copy link
Member

ausi commented Feb 2, 2017

I’m not a fan of this solution. How about using the file size instead of the path for the hash? md5_file() could be an alternative too, but may be too slow.

@leofeyer
Copy link
Member

leofeyer commented Feb 2, 2017

I don't like the solution, either. But it seems to be the only backwards compatible way, doesn't it?

@ausi
Copy link
Member

ausi commented Feb 2, 2017

But it seems to be the only backwards compatible way, doesn't it?

Why? Using md5_file() or the file size would be compatible too I think.

How about making the path relative to the already available $cacheDir, would this solve your issue too @aschempp?

@aschempp
Copy link
Member Author

aschempp commented Feb 2, 2017

you mean relative as in ../../files/foobar.jpg?

@ausi
Copy link
Member

ausi commented Feb 2, 2017

yes

@aschempp
Copy link
Member Author

aschempp commented Feb 2, 2017

I guess that would work… the only difference would be that ../../ (from default assets/images) would be in the cache path hash, but that should not matter…

shall I update the PR ?

@ausi
Copy link
Member

ausi commented Feb 2, 2017

Then I think we should do it that way. Should I create a new PR, or do you want to change this one?

.gitignore Outdated
@@ -1,2 +1,3 @@
# Vendor
/vendor/
/composer.lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to this PR I think and is already fixed in the master branch.

src/Resizer.php Outdated
[
Path::makeRelative($path, $this->cacheDir),
filemtime($path),
$coordinates->getHash()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma is missing here I think.

@aschempp
Copy link
Member Author

aschempp commented Feb 7, 2017

so do we agree on the general implementation (apart from coding style and unrelated changes) ;-)

@ausi
Copy link
Member

ausi commented Feb 7, 2017

Yes, I do.

@leofeyer leofeyer closed this Feb 14, 2017
@leofeyer leofeyer changed the base branch from hotfix/0.3.2 to master February 14, 2017 13:47
@leofeyer leofeyer reopened this Feb 14, 2017
@ausi
Copy link
Member

ausi commented Mar 22, 2017

I will merge this one. @leofeyer do you agree?

@leofeyer
Copy link
Member

Yes, if you remove the unrelated changes and add a unit test.

@ausi ausi changed the base branch from master to hotfix/0.3.3 March 22, 2017 18:48
@ausi ausi merged commit 47e1646 into contao:hotfix/0.3.3 Mar 22, 2017
@leofeyer
Copy link
Member

Thank you @aschempp and @ausi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants