Skip to content

Commit

Permalink
Configure HTMLPurifier serializer cache path under the main applicati…
Browse files Browse the repository at this point in the history
…on cache.
  • Loading branch information
Furgas committed Apr 5, 2024
1 parent bd68552 commit f26bc7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ services:

Symfony\Component\HttpClient\NoPrivateNetworkHttpClient: ~

Packeton\Package\Updater:
calls:
- [setSerializerCachePath, ['%kernel.cache_dir%/html_purifier']]

Okvpn\Expression\TwigLanguage:
arguments:
$options:
Expand Down
14 changes: 14 additions & 0 deletions src/Package/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Updater implements UpdaterInterface
],
];

private ?string $serializerCachePath = null;

public function __construct(
protected ManagerRegistry $doctrine,
protected DistConfig $distConfig,
Expand All @@ -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}
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f26bc7b

Please sign in to comment.