3 namespace Wallabag\CoreBundle\Form\DataTransformer
;
5 use Symfony\Component\Form\DataTransformerInterface
;
8 * Transforms a comma-separated list to a proper PHP array.
9 * Example: the string "foo, bar" will become the array ["foo", "bar"].
11 class StringToListTransformer
implements DataTransformerInterface
19 * @param string $separator The separator used in the list
21 public function __construct($separator = ',')
23 $this->separator
= $separator;
27 * Transforms a list to a string.
29 * @param array|null $list
33 public function transform($list)
39 return implode($this->separator
, $list);
43 * Transforms a string to a list.
45 * @param string $string
49 public function reverseTransform($string)
51 if ($string === null) {
55 return array_values(array_filter(array_map('trim', explode($this->separator
, $string))));