diff --git a/config/services.yaml b/config/services.yaml index 7da1ddd7..90e7c0e5 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -230,6 +230,10 @@ services: Symfony\Component\HttpClient\NoPrivateNetworkHttpClient: ~ + Packeton\Package\Updater: + calls: + - [setSerializerCachePath, ['%kernel.cache_dir%/html_purifier']] + Okvpn\Expression\TwigLanguage: arguments: $options: diff --git a/src/Package/Updater.php b/src/Package/Updater.php index df5c7de2..c76c9a1d 100644 --- a/src/Package/Updater.php +++ b/src/Package/Updater.php @@ -86,6 +86,8 @@ class Updater implements UpdaterInterface ], ]; + private ?string $serializerCachePath = null; + public function __construct( protected ManagerRegistry $doctrine, protected DistConfig $distConfig, @@ -97,6 +99,15 @@ public function __construct( ErrorHandler::register(); } + public function setSerializerCachePath(string $serializerCachePath): void + { + if (!mkdir($serializerCachePath, true) && !is_dir($serializerCachePath)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $serializerCachePath)); + } + + $this->serializerCachePath = $serializerCachePath; + } + /** * {@inheritdoc} */ @@ -894,6 +905,9 @@ private function prepareReadme(string $readme, ?string $host = null, ?string $ow $config->set('HTML.AllowedAttributes', implode(',', $attributes)); $config->set('Attr.EnableID', true); $config->set('Attr.AllowedFrameTargets', ['_blank']); + if ($this->serializerCachePath !== null) { + $config->set('Cache.SerializerPath', $this->serializerCachePath); + } // add custom HTML tag definitions $def = $config->getHTMLDefinition(true);