3 namespace Wallabag\CoreBundle\Form\DataTransformer
;
5 use Doctrine\Common\Persistence\ObjectManager
;
6 use Symfony\Component\Form\DataTransformerInterface
;
7 use Symfony\Component\Form\Exception\TransformationFailedException
;
10 * Transforms a comma-separated list to a proper PHP array.
11 * Example: the string "foo, bar" will become the array ["foo", "bar"]
13 class StringToListTransformer
implements DataTransformerInterface
21 * @param string $separator The separator used in the list.
23 public function __construct($separator = ',')
25 $this->separator
= $separator;
29 * Transforms a list to a string.
31 * @param array|null $list
35 public function transform($list)
41 return implode($this->separator
, $list);
45 * Transforms a string to a list.
47 * @param string $string
51 public function reverseTransform($string)
53 if ($string === null) {
57 return array_values(array_filter(array_map('trim', explode($this->separator
, $string))));