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

Custom path callable #282

Merged
merged 5 commits into from
Apr 25, 2023

Conversation

mlazze
Copy link
Contributor

@mlazze mlazze commented Jul 21, 2020

This would allow to customize the cache path fully.

An alternative would be to call the callable at the end of getCachePath with all the calculated parts (sourcePath, md5, groupCacheInFolders, cachePathPrefix, cacheWithFileExtensions, ext).

I also bound this to the Server instance so that we may its method within the callable.

@tgalopin
Copy link
Member

What's your use case for this? I'm not fundamentally against adding it, but I don't think users need should care about the internal structure of the cache. I may be missing a valid use case though.

@ADmad
Copy link
Collaborator

ADmad commented Jan 24, 2021

@tgalopin One of goals for Glide 2.0 stated by @reinink in #170 is: Serve cached images via web server.

Until the same is supported/implemented, allowing users to customize the cache path using a callable could help users achieve the same in the meantime.

@tgalopin
Copy link
Member

That's an interesting idea indeed. @mlazze are you still interested in finalizing this PR? It needs rebasing and I have some comments on the code but I prefer to ask before moving forward on this PR :) .

@mlazze
Copy link
Contributor Author

mlazze commented Jan 25, 2021

Yes, i'm customizing the path callable to allow the ws to cache images. I'm also using that to add custom meta information to the path (that's beyond the scope of this library, but i still need that :D ) , so this allows me to customize everything about the cache path generation.

I'm willing to finalize this PR and rebase it (in a few days :D)

@mlazze mlazze force-pushed the customPathCallable branch 2 times, most recently from 18fdada to 0dd257b Compare February 25, 2021 15:07
@mlazze
Copy link
Contributor Author

mlazze commented Feb 25, 2021

Rebased on master.

7.2 fails for missing gd library, i'm not sure why

src/Server.php Outdated Show resolved Hide resolved
@ADmad
Copy link
Collaborator

ADmad commented Mar 3, 2021

7.2 fails for missing gd library, i'm not sure why

Rebasing your branch onto upstream master should fix that.

@mlazze mlazze force-pushed the customPathCallable branch from 0dd257b to cdd9aa0 Compare March 5, 2021 13:59
@mlazze mlazze force-pushed the customPathCallable branch from cdd9aa0 to 5cb1378 Compare March 5, 2021 14:03
@mlazze
Copy link
Contributor Author

mlazze commented Mar 5, 2021

Hello, just switched from callable to Closure and rebased on master.

src/Server.php Outdated Show resolved Hide resolved
src/Server.php Outdated Show resolved Hide resolved
src/ServerFactory.php Outdated Show resolved Hide resolved
@mlazze
Copy link
Contributor Author

mlazze commented Mar 5, 2021

I may also add return type hints if needed, but i'm not seeing them in the codebase.

@@ -349,6 +375,12 @@ public function getCacheWithFileExtensions()
*/
public function getCachePath($path, array $params = [])
{
$customCallable = $this->getCachePathCallable();
if (null !== $customCallable) {
$boundCallable = \Closure::bind($customCallable, $this, self::class);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you are binding current object's context can you please add a test for it too. For e.g. calling $this->getSourcePath() inside the callable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mlazze Ping

@huiyang
Copy link

huiyang commented Jul 30, 2021

Is there any update?
I need this update to serve image cache directly from web server without go through php.
Is the review pending changes from @mlazze ?

Appreciate for the effort anyway.

@huiyang
Copy link

huiyang commented Mar 1, 2023

Is there any update for this?

Thanks.

@ADmad ADmad changed the base branch from master to cache-path-callable April 25, 2023 07:04
@ADmad ADmad merged commit 2f454c4 into thephpleague:cache-path-callable Apr 25, 2023
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.

4 participants