Skip to content

Commit 68dff8c

Browse files
committed
check for cache dir
1 parent 4832fc5 commit 68dff8c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

backend/app/Services/Infrastructure/HtmlPurifier/HtmlPurifierService.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
use HTMLPurifier;
66
use HTMLPurifier_Config;
7+
use Illuminate\Support\Facades\File;
78

89
class HtmlPurifierService
910
{
10-
public function __construct(
11-
private readonly HTMLPurifier $htmlPurifier
12-
)
11+
private HTMLPurifier_Config $config;
12+
13+
public function __construct(private readonly HTMLPurifier $htmlPurifier)
1314
{
15+
$this->config = HTMLPurifier_Config::createDefault();
16+
17+
$cachePath = storage_path('app/htmlpurifier');
18+
File::ensureDirectoryExists($cachePath, 0755);
19+
20+
$this->config->set('Cache.SerializerPath', $cachePath);
1421
}
1522

1623
public function purify(?string $html): string
@@ -19,9 +26,6 @@ public function purify(?string $html): string
1926
return '';
2027
}
2128

22-
$config = HTMLPurifier_Config::createDefault();
23-
$config->set('Cache.SerializerPath', base_path('storage/framework/cache'));
24-
25-
return $this->htmlPurifier->purify($html, $config);
29+
return $this->htmlPurifier->purify($html, $this->config);
2630
}
2731
}

0 commit comments

Comments
 (0)