aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php')
-rw-r--r--vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php b/vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php
new file mode 100644
index 00000000..1dfe8900
--- /dev/null
+++ b/vendor/symfony/form/Symfony/Component/Form/CallbackTransformer.php
@@ -0,0 +1,70 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Form;
13
14class CallbackTransformer implements DataTransformerInterface
15{
16 /**
17 * The callback used for forward transform
18 * @var \Closure
19 */
20 private $transform;
21
22 /**
23 * The callback used for reverse transform
24 * @var \Closure
25 */
26 private $reverseTransform;
27
28 /**
29 * Constructor.
30 *
31 * @param \Closure $transform The forward transform callback
32 * @param \Closure $reverseTransform The reverse transform callback
33 */
34 public function __construct(\Closure $transform, \Closure $reverseTransform)
35 {
36 $this->transform = $transform;
37 $this->reverseTransform = $reverseTransform;
38 }
39
40 /**
41 * Transforms a value from the original representation to a transformed representation.
42 *
43 * @param mixed $data The value in the original representation
44 *
45 * @return mixed The value in the transformed representation
46 *
47 * @throws UnexpectedTypeException when the argument is not a string
48 * @throws TransformationFailedException when the transformation fails
49 */
50 public function transform($data)
51 {
52 return call_user_func($this->transform, $data);
53 }
54
55 /**
56 * Transforms a value from the transformed representation to its original
57 * representation.
58 *
59 * @param mixed $data The value in the transformed representation
60 *
61 * @return mixed The value in the original representation
62 *
63 * @throws UnexpectedTypeException when the argument is not of the expected type
64 * @throws TransformationFailedException when the transformation fails
65 */
66 public function reverseTransform($data)
67 {
68 return call_user_func($this->reverseTransform, $data);
69 }
70}