diff --git a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php
index 8dd3fa37..061a4043 100644
--- a/src/DependencyInjection/ExerciseHTMLPurifierExtension.php
+++ b/src/DependencyInjection/ExerciseHTMLPurifierExtension.php
@@ -8,17 +8,17 @@
use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistryInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
-use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Extension\Extension;
+use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
+use Symfony\Component\DependencyInjection\Reference;
class ExerciseHTMLPurifierExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('html_purifier.xml');
+ $loader->load('services.php');
$configs = $this->processConfiguration(new Configuration(), $configs);
@@ -30,8 +30,6 @@ public function load(array $configs, ContainerBuilder $container): void
}
$serializerPaths = [];
- // Drop when require Symfony > 3.4
- $registerAlias = method_exists($container, 'registerAliasForArgument');
foreach ($configs['html_profiles'] as $name => $definition) {
$configId = "exercise_html_purifier.config.$name";
@@ -71,7 +69,7 @@ public function load(array $configs, ContainerBuilder $container): void
$serializerPaths[] = $definition['config']['Cache.SerializerPath'];
}
- if ($registerAlias && $default) {
+ if ($default) {
$container->registerAliasForArgument($id, \HTMLPurifier::class, "$name.purifier");
}
}
diff --git a/src/HTMLPurifierConfigFactory.php b/src/HTMLPurifierConfigFactory.php
index 6eac59fb..e8e88e4e 100644
--- a/src/HTMLPurifierConfigFactory.php
+++ b/src/HTMLPurifierConfigFactory.php
@@ -28,7 +28,7 @@ public static function create(
array $parents = [],
array $attributes = [],
array $elements = [],
- array $blankElements = []
+ array $blankElements = [],
): \HTMLPurifier_Config {
if ($defaultConfig) {
$config = \HTMLPurifier_Config::inherit($defaultConfig);
diff --git a/src/Resources/config/html_purifier.xml b/src/Resources/config/html_purifier.xml
deleted file mode 100644
index d3bfac09..00000000
--- a/src/Resources/config/html_purifier.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php
new file mode 100644
index 00000000..dad69f2d
--- /dev/null
+++ b/src/Resources/config/services.php
@@ -0,0 +1,40 @@
+services()
+ ->set('exercise_html_purifier.cache_warmer.serializer', SerializerCacheWarmer::class)
+ ->tag('kernel.cache_warmer')
+ ->args([
+ abstract_arg('cache paths'),
+ abstract_arg('profiles'),
+ service(HTMLPurifiersRegistryInterface::class),
+ service('filesystem'),
+ ])
+
+ ->set('exercise_html_purifier.form.text_type_extension', HTMLPurifierTextTypeExtension::class)
+ ->tag('form.type_extension', ['extended_type' => TextType::class])
+ ->args([
+ service(HTMLPurifiersRegistryInterface::class),
+ ])
+
+ ->set('exercise_html_purifier.twig.extension', HTMLPurifierExtension::class)
+ ->tag('twig.extension')
+
+ ->set('exercise_html_purifier.twig.runtime', HTMLPurifierRuntime::class)
+ ->tag('twig.runtime')
+ ->args([
+ service(HTMLPurifiersRegistryInterface::class),
+ ]);
+};
diff --git a/tests/HTMLPurifierConfigFactoryTest.php b/tests/HTMLPurifierConfigFactoryTest.php
index 70dfec9c..ff780bfe 100644
--- a/tests/HTMLPurifierConfigFactoryTest.php
+++ b/tests/HTMLPurifierConfigFactoryTest.php
@@ -61,7 +61,7 @@ public static function buildHTMLDefinition(
\HTMLPurifier_HTMLDefinition $def,
array $attributes,
array $elements,
- array $blankElements
+ array $blankElements,
): void {
++self::$calledBuild;
parent::buildHTMLDefinition($def, $attributes, $elements, $blankElements);