ReversedTransformer.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form;
  11. /**
  12. * Reverses a transformer.
  13. *
  14. * When the transform() method is called, the reversed transformer's
  15. * reverseTransform() method is called and vice versa.
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. class ReversedTransformer implements DataTransformerInterface
  20. {
  21. protected $reversedTransformer;
  22. public function __construct(DataTransformerInterface $reversedTransformer)
  23. {
  24. $this->reversedTransformer = $reversedTransformer;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function transform($value)
  30. {
  31. return $this->reversedTransformer->reverseTransform($value);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function reverseTransform($value)
  37. {
  38. return $this->reversedTransformer->transform($value);
  39. }
  40. }