stevebauman/purify

Vapor / Other storage drivers Support

Closed this issue · 7 comments

Hello, my team and I ran into an issue when trying to use this with Vapor and realized that the 'Cache.SerializerPath' must be a local directory on the webserver, which Vapor doesn't support.

Is it possible to add support for S3 or other Storage drivers to this and are there any plans for that?

Hi @joshtorres,

That’d be great to support it. I’m open to PRs implementing this. I’m a bit swamped with other open source projects at the moment so if you’d like to tackle it then I’d for sure work with you to get this merged 👍

Ok thanks. We will look into this.

I'm afraid this feature request won't be viable in a straightforward way. It's the subdependency ezyang/html-purifier that manages the cache write, and as you can see below they use a plain file_put_contents call:

https://github.com/ezyang/htmlpurifier/blob/3fc193c7553ca9eb3431a48708c17ad081cc1e64/library/HTMLPurifier/DefinitionCache/Serializer.php#L199

Hi all,

I'm going to have the same problem - noting that this is a cache storage, I wouldn't store it on S3, but in the cache.

If a PR is raised, it would be better to wrap up config around Laravel's Caching system rather than storage system.

I did have a go at this before (#34), and will see where I got to. Maybe v5's config will make it easier.

Hey there @kurucu, v5.0 has been released, but it doesn't come with the ability to store the cache in a cloud location. Like @Propaganistas mentioned, this is tricky, because the core HtmlPurifier package uses file_put_contents() in private method for it's built in serializer definition:

https://github.com/ezyang/htmlpurifier/blob/3fc193c7553ca9eb3431a48708c17ad081cc1e64/library/HTMLPurifier/DefinitionCache/Serializer.php#L197-L199

However, I think we should be able to include our "cloud" serializer definition class in Purify, as I believe the serializer is overridable via the Cache.DefinitionImpl config option:

http://htmlpurifier.org/live/configdoc/plain.html#Cache.DefinitionImpl

I'll take a look at this over the weekend 👍

Hi guys!

I've just updated Purify with the ability to configure the serializer cache mechanism:

purify/config/purify.php

Lines 84 to 93 in 562bec0

'serializer' => [
'driver' => env('CACHE_DRIVER', 'file'),
'cache' => \Stevebauman\Purify\Cache\CacheDefinitionCache::class,
],
// 'serializer' => [
// 'disk' => env('FILESYSTEM_DISK', 'local'),
// 'path' => 'purify',
// 'cache' => \Stevebauman\Purify\Cache\FilesystemDefinitionCache::class,
// ],

This means, you may use Laravel's filesystem, or cache. 🎉

Would any of you be able to test this update out locally to ensure your needs are met? I ask because this will be a new major version release, and I want to ensure your needs are met before deploying. You may do so by updating purify in your composer.json to:

"stevebauman/purify": "dev-master",

Then, replacing the purifiy.serializer config key with the updated structure:

Before:

'serializer' => storage_path('app/purify'),

After:

purify/config/purify.php

Lines 84 to 87 in 562bec0

'serializer' => [
'driver' => env('CACHE_DRIVER', 'file'),
'cache' => \Stevebauman\Purify\Cache\CacheDefinitionCache::class,
],

Thanks for your time! 🙏

v6.0.0 has been released with these changes 👍