tgalopin / html-sanitizer

Sanitize untrustworthy HTML user input
MIT License
390 stars 41 forks source link

set fluent the SanitizerBuilder methods #32

Closed Ioni14 closed 5 years ago

Ioni14 commented 5 years ago

I added the possibility to chain the SanitizerBuilder methods like the classical Builder pattern.

This can enhance readability. For example:

public static function sanitize($html)
{
    return (new SanitizerBuilder())
        ->registerExtension(new BasicExtension())
        ->registerExtension(new ListExtension())
        ->registerExtension(new CodeExtension())
        ->registerExtension(new TableExtension())
        ->registerExtension(new IframeExtension())
        ->registerExtension(new DetailsExtension())
        ->registerExtension(new ExtraExtension())
        ->registerExtension(new BpmExtension())
        ->build(self::SANITIZER_CONFIG)
        ->sanitize($html);
}

I also added the ext-intl in the composer.json require, the tests failed because I had not this extension.

tgalopin commented 5 years ago

That's a great idea, thank you :) .