@@ -22,8 +22,13 @@ class ConfiguredHtmlPurifier
2222
2323 public function __construct ()
2424 {
25+ // This is done by the web-server at run-time, with the existing
26+ // storage/framework/cache folder to ensure we're using a server-writable folder.
27+ $ cachePath = storage_path ('framework/cache/purifier ' );
28+ $ this ->createCacheFolderIfNeeded ($ cachePath );
29+
2530 $ config = HTMLPurifier_HTML5Config::createDefault ();
26- $ this ->setConfig ($ config );
31+ $ this ->setConfig ($ config, $ cachePath );
2732 $ this ->resetCacheIfNeeded ($ config );
2833
2934 $ htmlDef = $ config ->getDefinition ('HTML ' , true , true );
@@ -34,6 +39,13 @@ public function __construct()
3439 $ this ->purifier = new HTMLPurifier ($ config );
3540 }
3641
42+ protected function createCacheFolderIfNeeded (string $ cachePath ): void
43+ {
44+ if (!file_exists ($ cachePath )) {
45+ mkdir ($ cachePath , 0777 , true );
46+ }
47+ }
48+
3749 protected function resetCacheIfNeeded (HTMLPurifier_Config $ config ): void
3850 {
3951 if (self ::$ cachedChecked ) {
@@ -53,9 +65,9 @@ protected function resetCacheIfNeeded(HTMLPurifier_Config $config): void
5365 self ::$ cachedChecked = true ;
5466 }
5567
56- protected function setConfig (HTMLPurifier_Config $ config ): void
68+ protected function setConfig (HTMLPurifier_Config $ config, string $ cachePath ): void
5769 {
58- $ config ->set ('Cache.SerializerPath ' , storage_path ( ' framework/purifier ' ) );
70+ $ config ->set ('Cache.SerializerPath ' , $ cachePath );
5971 $ config ->set ('Core.AllowHostnameUnderscore ' , true );
6072 $ config ->set ('CSS.AllowTricky ' , true );
6173 $ config ->set ('HTML.SafeIframe ' , true );
0 commit comments