-
Notifications
You must be signed in to change notification settings - Fork 28
/
StripTagsTransformer.php
51 lines (45 loc) · 1.06 KB
/
StripTagsTransformer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace SimpleThings\FormExtraBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
/**
* Utilizes strip_tags to easy strip tags from fields.
*
* example:
* $builder->get('my_field')->appendNormTransformer(new StripTagsTransformer('<p>'));
*
* @author Henrik Bjornskov <henrik@bjrnskov.dk>
*/
class StripTagsTransformer implements DataTransformerInterface
{
/**
* @var string
*/
protected $allowedTags = '';
/**
* @param string $allowedTags list of tags to allow see php.net/strip_tags
*/
public function __construct($allowedTags = '')
{
$this->allowedTags = $allowedTags;
}
/**
* Not Used
*
* @param string $value
* @return string
*/
public function transform($value)
{
return $value;
}
/**
* Cleans the parameter value by called strip_tags.
*
* @param string $value
* @return string
*/
public function reverseTransform($value)
{
return strip_tags($value, $this->allowedTags);
}
}