]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form
;
14 class CallbackTransformer
implements DataTransformerInterface
17 * The callback used for forward transform
23 * The callback used for reverse transform
26 private $reverseTransform;
31 * @param \Closure $transform The forward transform callback
32 * @param \Closure $reverseTransform The reverse transform callback
34 public function __construct(\Closure
$transform, \Closure
$reverseTransform)
36 $this->transform
= $transform;
37 $this->reverseTransform
= $reverseTransform;
41 * Transforms a value from the original representation to a transformed representation.
43 * @param mixed $data The value in the original representation
45 * @return mixed The value in the transformed representation
47 * @throws UnexpectedTypeException when the argument is not a string
48 * @throws TransformationFailedException when the transformation fails
50 public function transform($data)
52 return call_user_func($this->transform
, $data);
56 * Transforms a value from the transformed representation to its original
59 * @param mixed $data The value in the transformed representation
61 * @return mixed The value in the original representation
63 * @throws UnexpectedTypeException when the argument is not of the expected type
64 * @throws TransformationFailedException when the transformation fails
66 public function reverseTransform($data)
68 return call_user_func($this->reverseTransform
, $data);