CustomNormalizer.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Symfony\Component\Serializer\Normalizer;
  3. use Symfony\Component\Serializer\SerializerInterface;
  4. /*
  5. * This file is part of the Symfony framework.
  6. *
  7. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. /**
  13. * @author Jordi Boggiano <j.boggiano@seld.be>
  14. */
  15. class CustomNormalizer extends AbstractNormalizer implements NormalizerInterface
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function normalize($object, $format, $properties = null)
  21. {
  22. return $object->normalize($this, $format, $properties);
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function denormalize($data, $class, $format = null)
  28. {
  29. $object = new $class;
  30. $object->denormalize($this, $data, $format);
  31. return $object;
  32. }
  33. /**
  34. * Checks if the given class implements the NormalizableInterface.
  35. *
  36. * @param ReflectionClass $class A ReflectionClass instance of the class
  37. * to serialize into or from.
  38. * @param string $format The format being (de-)serialized from or into.
  39. * @return Boolean
  40. */
  41. public function supports(\ReflectionClass $class, $format = null)
  42. {
  43. return $class->implementsInterface('Symfony\Component\Serializer\Normalizer\NormalizableInterface');
  44. }
  45. }