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

[1.0][filter] Dynamic filters #313

Merged
merged 3 commits into from
Mar 10, 2014
Merged

Conversation

makasim
Copy link
Collaborator

@makasim makasim commented Feb 3, 2014

This attempts to address #268. Other solutions\issues: #42, #271

Use cases:

  • Twig:
{% set runtimeConfig = {"thumbnail": {"size": [50, 50] }} %}
<img src="{{ '/images/dream.jpg' | imagine_filter('thumbnail', runtimeConfig) }}" />
  • Php:
<?php

$cacheManager->getBroserPath($path, $filter, array(
    'thumbnail' => array(
        'size' => array(50, 50),
    )
));

Here you can see filter url:

http://liip-imagine-sandbox.dev/appp.php/media/cache/thumbnail_web_path/images/dream.jpg?filters%5Bthumbnail%5D%5Bsize%5D%5B0%5D=50&filters%5Bthumbnail%5D%5Bsize%5D%5B1%5D=50&_hash=PkE1ct4QN1BJct6P6Pqfmb%2FelZ%2F99tFgZjsn29zTs8A%3D

and resolved one:

http://liip-imagine-sandbox.dev/media/cache/thumbnail_web_path/PkE1ct4Q/images/dream.jpg

The url contains PkE1ct4Q in path to not mess with pre configured filter caches. It is not possible to remove a single custom cache (at least you the whole path including PkE1ct4Q). but remove all has to work quite well.

$filterPostfix = '';
if ($runtimeFilters = $request->query->get('filters', array())) {
$signer = new UriSigner('aSecret');
if (false == $signer->check($request->getRequestUri())) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here I want to reused UriSigner from HttpKernel to check url was not modified

@makasim
Copy link
Collaborator Author

makasim commented Feb 10, 2014

@havvg the logic is ready for review. I still have to fix some tests and add new

@makasim
Copy link
Collaborator Author

makasim commented Feb 18, 2014

@havvg added tests, updated README.md. Ready for review

@makasim
Copy link
Collaborator Author

makasim commented Feb 20, 2014

@havvg ping

{
if (!empty($runtimeConfig)) {
return $this->generateUrl($path, $filter, $runtimeConfig);

Choose a reason for hiding this comment

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

I dont like this place because it generates url of local controller

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ASKozienko I dont like it neither. In future it has to be optimized, for now I think we can start with simple solution and later change implementation.

@ASKozienko
Copy link

looks good in general

@makasim
Copy link
Collaborator Author

makasim commented Feb 24, 2014

@havvg ping

1 similar comment
@makasim
Copy link
Collaborator Author

makasim commented Mar 3, 2014

@havvg ping

@makasim
Copy link
Collaborator Author

makasim commented Mar 4, 2014

@havvg is not responding for some time. what should I do to proceed with my open PRs Any thoughts @lsmith77 @dbu?

I can wait for @havvg if I hear some words from him. Could I request a maintainer rights?

@havvg
Copy link
Contributor

havvg commented Mar 4, 2014

+1 on maintainer rights. I'm quite busy these days, and got some illness, too :(

@makasim
Copy link
Collaborator Author

makasim commented Mar 4, 2014

@havvg oh you are here (:. I wish you get better very soon.

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 4, 2014

I have given @makasim commit rights.

@havvg
Copy link
Contributor

havvg commented Mar 4, 2014

Thanks!

@makasim
Copy link
Collaborator Author

makasim commented Mar 4, 2014

@lsmith77 thanks, is there any policy I have to follow as a maintainer. just a few words about what I can and what I cannot (: to make things clear.

@antonbabenko
Copy link

Congratulations @makasim !

@havvg
Copy link
Contributor

havvg commented Mar 4, 2014

@makasim The only real policy right now: Keep the master branch stable (by following semver.org).
The develop branch is unstable, free for any re-factoring (as you/we did already). Please do not push any branches into this repository, as they will show up on packagist. Everything should be done using a PR.

Feel free to maintain :-)

@makasim
Copy link
Collaborator Author

makasim commented Mar 4, 2014

@havvg thanks, will do

@makasim
Copy link
Collaborator Author

makasim commented Mar 5, 2014

I am going to merge this tomorrow. (if tests pass ofcourse)

makasim added a commit that referenced this pull request Mar 10, 2014
@makasim makasim merged commit f0f33f0 into liip:develop Mar 10, 2014
@makasim makasim deleted the filters-dynamic branch March 10, 2014 10:49
@trsteel88
Copy link
Contributor

Will the use of this logic be added to the documentation soon?

@makasim
Copy link
Collaborator Author

makasim commented Mar 10, 2014

@trsteel88 it is already there read README.md. Search for You can also pass some options at runtime:. In the controller you have to use CacheManager::getBrowserPath method.

@makasim
Copy link
Collaborator Author

makasim commented Mar 10, 2014

@trsteel88 please note you have to read the doc of develop branch

@trsteel88
Copy link
Contributor

Thanks @makasim.

I just wanted to raise 1 issue with this implementation. Currently, you are generating a hash to authenticate that the values are correct. I think this should be split into several "directories".

Eg, say the generated hash is "S8rrlhhQ" I think it should be split up so it becomes "S8r/rlh/hQ" (or something similar). Otherwise, if a website has 100,000 images it is going to create up to 100,000 folders inside 1 (or more) directories. Splitting it into several directories will scatter the structure a bit more. This will make it much easier to navigate through ftp or viewing the folder and doing "ls -la".

@makasim
Copy link
Collaborator Author

makasim commented Mar 11, 2014

@trsteel88 Good point. I've created an issue #341

if ('\\' === $pathinfo['dirname']) {
$pathinfo['dirname'] = '';
}
$filterUrl = $this->router->generate('_imagine_'.$filter, $params, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the $params be sorted alphabetically (by key)?

Eg, say your dynamic filter is {width: 100, height: 200, extra: {'key': 'val'}}

If I then generate a image using {height: 200, width: 100, extra: {'key': 'val'}} it will generate a different hash.

I think that these parameters should be sorted to try and minimise duplicate image generation. Obviously the params would need to cascade incase their are multiple array within the config.

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's a good idea, you could create an issue so we dont forget about it,

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

6 participants