PHPackages                             exercise/htmlpurifier-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. exercise/htmlpurifier-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

exercise/htmlpurifier-bundle
============================

HTMLPurifier integration for your Symfony project

5.2(6mo ago)27911.3M—4%56[1 PRs](https://github.com/Exercise/HTMLPurifierBundle/pulls)14MITPHPPHP ^8.1CI passing

Since Apr 10Pushed 6mo ago18 watchersCompare

[ Source](https://github.com/Exercise/HTMLPurifierBundle)[ Packagist](https://packagist.org/packages/exercise/htmlpurifier-bundle)[ Docs](https://github.com/Exercise/HTMLPurifierBundle)[ RSS](/packages/exercise-htmlpurifier-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (34)Used By (14)

[![Total Downloads](https://camo.githubusercontent.com/4f736596ebe5b3b7f1367056233b94aa69ce8939bb9105d4a24993c6fe60d757/68747470733a2f2f706f7365722e707567782e6f72672f65786572636973652f68746d6c70757269666965722d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/exercise/htmlpurifier-bundle)[![Latest Stable Version](https://camo.githubusercontent.com/5c3a1f829fffe9099b3b9b9c0dee1e57bec0b15bc9658c604ed215f34dee7da1/68747470733a2f2f706f7365722e707567782e6f72672f65786572636973652f68746d6c70757269666965722d62756e646c652f762f737461626c65)](https://packagist.org/packages/exercise/htmlpurifier-bundle)[![License](https://camo.githubusercontent.com/509e1273270cc8bf8b1748daa9a942d80ffe6c75ce3fc160dd609217bcec6494/68747470733a2f2f706f7365722e707567782e6f72672f65786572636973652f68746d6c70757269666965722d62756e646c652f6c6963656e7365)](https://packagist.org/packages/exercise/htmlpurifier-bundle)[![Build Status](https://camo.githubusercontent.com/019ce73ad11b157e898a6191bbe2d5f9359a5d1f6ad0dcd2122793b340e8dd6b/68747470733a2f2f7472617669732d63692e6f72672f45786572636973652f48544d4c507572696669657242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Exercise/HTMLPurifierBundle)

ExerciseHTMLPurifierBundle
==========================

[](#exercisehtmlpurifierbundle)

This bundle integrates [HTMLPurifier](http://htmlpurifier.org/) into Symfony.

Installation
------------

[](#installation)

Install the bundle:

```
$ composer require exercise/htmlpurifier-bundle
```

Configuration
-------------

[](#configuration)

If you do not explicitly configure this bundle, an HTMLPurifier service will be defined as `exercise_html_purifier.default`. This behavior is the same as if you had specified the following configuration:

```
# config/packages/exercise_html_purifier.yaml

exercise_html_purifier:
    default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
    # 493 int => ocl "0755"
    default_cache_serializer_permissions: 493
```

The `default` profile is special, it is *always* defined and its configuration is inherited by all custom profiles. `exercise_html_purifier.default` is the default service using the base configuration.

```
# config/packages/exercise_html_purifier.yaml

exercise_html_purifier:
    default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
    html_profiles:
        custom:
            config:
                Core.Encoding: 'ISO-8859-1'
                HTML.Allowed: 'a[href|target],p,br'
                Attr.AllowedFrameTargets: '_blank'
```

In this example, a `exercise_html_purifier.custom` service will also be defined, which includes cache, encoding, HTML tags and attributes options. Available configuration options may be found in HTMLPurifier's [configuration documentation](http://htmlpurifier.org/live/configdoc/plain.html).

**Note:** If you define a `default` profile but omit `Cache.SerializerPath`, it will still default to the path above. You can specify a value of `null` for the option to suppress the default path.

Autowiring
----------

[](#autowiring)

By default type hinting `\HtmlPurifier` in your services will autowire the `exercise_html_purifier.default` service. To override it and use your own config as default autowired services just add this configuration:

```
# config/services.yaml
services:
    #...

    exercise_html_purifier.default: '@exercise_html_purifier.custom'
```

### Using a custom purifier class as default

[](#using-a-custom-purifier-class-as-default)

If you want to use your own class as default purifier, define the new alias as below:

```
# config/services.yaml
services:
    # ...

    exercise_html_purifier.default: '@App\Html\CustomHtmlPurifier'
```

### Argument binding

[](#argument-binding)

The bundle also leverages the alias argument binding for each profile. So the following config:

```
    html_profiles:
        blog:
            # ...
        gallery:
            # ...
```

will register the following binding:

```
 // default config is bound whichever argument name is used
public function __construct(\HTMLPurifier $purifier) {}
public function __construct(\HTMLPurifier $htmlPurifier) {}
public function __construct(\HTMLPurifier $blogPurifier) {} // blog config
public function __construct(\HTMLPurifier $galleryPurifier) {} // gallery config
```

Form Type Extension
-------------------

[](#form-type-extension)

This bundles provides a form type extension for filtering form fields with HTMLPurifier. Purification is done early during the PRE\_SUBMIT event, which means that client data will be filtered before being bound to the form.

Two options are automatically available in all `TextType` based types:

```
