This bundle integrates htmLawed with Symfony2. It allows you to define
htmLawed configuration profiles, which are exposed as services implementing
ValueTransformerInterface
. These transformers can easily be attached to form
fields for input sanitization.
Add HtmLawedBundle to your src/
directory:
$ git submodule add git://github.com/opensky/HtmLawedBundle.git src/OpenSky/Bundle/HtmLawedBundle
If the src/
directory is already configured in your project's autoload.php
via registerNamespaceFallback()
, no changes should be necessary. Otherwise,
either define the fallback directory or explicitly add the "OpenSky" namespace:
# src/autoload.php
$loader->registerNamespaces(array(
'OpenSky' => __DIR__,
));
Add HtmLawedBundle to the registerBundles()
method of your application kernel:
public function registerBundles()
{
return array(
new OpenSky\Bundle\HtmLawedBundle\OpenSkyHtmLawedBundle(),
);
}
This bundle defines an HtmLawed
service, which is constructed with $config
and $spec
parameters. It implements a single process()
method that filters a
string value through the htmLawed()
function. The $config
and $spec
parameters provided during construction will be passed to htmLawed()
.
HtmLawedBundle may be configured with the following:
# app/config/config.yml
opensky_htmlawed:
file: %kernel.root_dir%/../vendor/htmlawed/htmLawed.php
profiles:
custom:
config:
comment: 0
cdata: 1
spec: a=title
default: ~
The above example would define two services: htmlawed.custom
and htmlawed.default
,
which will use their respective options as additional arguments to htmLawed()
when filtering input.
The file
option should be set with the path to the htmLawed vendor library.
The service container will ensure this file resource is loaded before one of the
configured services is constructed.
See also:
The services created by this bundle implement DataTransformerInterface
from
the Symfony2 Form component. Filtering is only done via reverseTransform()
.
The transform()
method is an identity function (i.e. it returns its input).
The htmLawed services should be assigned to form fields as a client transformer. Documentation is forthcoming.