Version 1
[yaffs-website] / vendor / symfony / serializer / Normalizer / CustomNormalizer.php
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
12 namespace Symfony\Component\Serializer\Normalizer;
13
14 /**
15  * @author Jordi Boggiano <j.boggiano@seld.be>
16  */
17 class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface
18 {
19     /**
20      * {@inheritdoc}
21      */
22     public function normalize($object, $format = null, array $context = array())
23     {
24         return $object->normalize($this->serializer, $format, $context);
25     }
26
27     /**
28      * {@inheritdoc}
29      */
30     public function denormalize($data, $class, $format = null, array $context = array())
31     {
32         $object = new $class();
33         $object->denormalize($this->serializer, $data, $format, $context);
34
35         return $object;
36     }
37
38     /**
39      * Checks if the given class implements the NormalizableInterface.
40      *
41      * @param mixed  $data   Data to normalize
42      * @param string $format The format being (de-)serialized from or into
43      *
44      * @return bool
45      */
46     public function supportsNormalization($data, $format = null)
47     {
48         return $data instanceof NormalizableInterface;
49     }
50
51     /**
52      * Checks if the given class implements the NormalizableInterface.
53      *
54      * @param mixed  $data   Data to denormalize from
55      * @param string $type   The class to which the data should be denormalized
56      * @param string $format The format being deserialized from
57      *
58      * @return bool
59      */
60     public function supportsDenormalization($data, $type, $format = null)
61     {
62         if (!class_exists($type)) {
63             return false;
64         }
65
66         return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
67     }
68 }