-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add adapter class for Exercise/HTMLPurifierBundle
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* This class provides easy integration with | ||
* {@link https://github.com/Exercise/HTMLPurifierBundle Exercise/HTMLPurifierBundle} | ||
* for Symfony-based apps. | ||
* | ||
* Because {@see \Exercise\HTMLPurifierBundle\HTMLPurifierConfigFactory} does not support | ||
* ustom config classes ({@link https://github.com/Exercise/HTMLPurifierBundle/issues/60 related issue}), | ||
* the injection of HTML5 config instance must be done inside the Purifier service itself. | ||
* | ||
* This class is not intended for direct use or outside Symfony apps, as it adds extra overhead | ||
* related to config instantiation, required to overcome limitations of the HTMLPurifierBundle. | ||
* | ||
* To use HTML5 purifier as a default profile add the following to <code>services.yaml</code>: | ||
* | ||
* <pre> | ||
* services: | ||
* exercise_html_purifier.default: | ||
* class: HTMLPurifier_HTML5 | ||
* tags: | ||
* - name: exercise.html_purifier | ||
* profile: default | ||
* </pre> | ||
* | ||
* To use it as any other profile please consult | ||
* {@link https://github.com/Exercise/HTMLPurifierBundle/blob/master/README.md HTMLPurifierBundle documentation}. | ||
*/ | ||
class HTMLPurifier_HTML5 extends HTMLPurifier | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __construct($config = null) | ||
{ | ||
parent::__construct(HTMLPurifier_HTML5Config::create($config)); | ||
} | ||
|
||
public function purify($html, $config = null) | ||
{ | ||
$config = $config ? HTMLPurifier_HTML5Config::create($config) : $this->config; | ||
return parent::purify($html, $config); | ||
} | ||
|
||
public function purifyArray($array_of_html, $config = null) | ||
{ | ||
$config = $config ? HTMLPurifier_HTML5Config::create($config) : $this->config; | ||
return parent::purifyArray($array_of_html, $config); | ||
} | ||
} |