Skip to content

Commit

Permalink
minor #74 Minor improvements in README (HeahDude)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Minor improvements in README

Commits
-------

95ac61e Minor improvements in README
  • Loading branch information
HeahDude committed Mar 10, 2020
2 parents d9d70e1 + 95ac61e commit b6c238e
Showing 1 changed file with 20 additions and 50 deletions.
70 changes: 20 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,29 @@ public function registerBundles()

## Configuration in Symfony 3

The configuration is the same as the following section, but the path should be
`app/config.yml` instead.

## Configuration in Symfony 4 and up

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:

```yaml
# app/config.yml
# config/packages/exercise_html_purifier.yaml

exercise_html_purifier:
default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
```
The `default` profile is special in that it is used as the configuration for the
`exercise_html_purifier.default` service as well as the base configuration for
other profiles you might define.
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.

```yaml
# app/config.yml
# config/packages/exercise_html_purifier.yaml
exercise_html_purifier:
default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
Expand All @@ -81,45 +87,12 @@ option to suppress the default path.

[configuration documentation]: http://htmlpurifier.org/live/configdoc/plain.html

## Configuration in Symfony 4 and up

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:

```yaml
# config/packages/exercise_html_purifier.yaml
exercise_html_purifier:
default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
```

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.

```yaml
# config/packages/exercise_html_purifier.yaml
exercise_html_purifier:
default_cache_serializer_path: 'tmp/htmlpurifier'
html_profiles:
default:
config:
Cache.SerializerPermissions: 777
custom:
config:
Core.Encoding: 'ISO-8859-1'
```

## 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 in you `app/config/services.yml` in you use symfony 3 or `config/services.yaml`
if you use symfony 4:
this configuration:

```yaml
# config/services.yaml
Expand All @@ -131,7 +104,8 @@ services:

### Using a custom purifier class as default

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

```yaml
# config/services.yaml
Expand All @@ -141,10 +115,7 @@ services:
exercise_html_purifier.default: '@App\Html\CustomHtmlPurifier'
```

In such case, the custom purifier will use its own defined configuration,
ignoring the bundle configuration.

### Argument binding
### Argument binding (Symfony >= 4.4)

The bundle also leverages the alias argument binding for each profile. So the
following config:
Expand All @@ -170,11 +141,10 @@ public function __construct(\HTMLPurifier $galleryPurifier) {} // gallery config
## Form Type Extension

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

The following example demonstrates one possible way to integrate an HTMLPurifier
transformer into a form by way of a custom field type:
Two options are automatically available in all `TextType` based types:

```php
<?php
Expand Down Expand Up @@ -213,7 +183,7 @@ This bundles registers a `purify` filter with Twig. Output from this filter is
marked safe for HTML, much like Twig's built-in escapers. The filter may be used
as follows:

``` jinja
```twig
{# Filters text's value through the "default" HTMLPurifier service #}
{{ text|purify }}
Expand Down Expand Up @@ -252,7 +222,7 @@ $builder
// ...
```

```jinja
```twig
{# in a template #}
{{ html_string|purify('custom') }}
```
Expand Down

0 comments on commit b6c238e

Please sign in to comment.