1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace Symfony\Component\Form;
- use Symfony\Component\Form\Exception\TransformationFailedException;
- use Symfony\Component\Form\Exception\UnexpectedTypeException;
- class CallbackTransformer implements DataTransformerInterface
- {
- private $transform;
- private $reverseTransform;
-
- public function __construct($transform, $reverseTransform)
- {
- if (!\is_callable($transform)) {
- throw new \InvalidArgumentException('Argument 1 should be a callable');
- }
- if (!\is_callable($reverseTransform)) {
- throw new \InvalidArgumentException('Argument 2 should be a callable');
- }
- $this->transform = $transform;
- $this->reverseTransform = $reverseTransform;
- }
-
- public function transform($data)
- {
- return \call_user_func($this->transform, $data);
- }
-
- public function reverseTransform($data)
- {
- return \call_user_func($this->reverseTransform, $data);
- }
- }
|