Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Normalizer/CustomNormalizer.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 use Symfony\Component\Serializer\SerializerAwareInterface; | |
15 use Symfony\Component\Serializer\SerializerAwareTrait; | |
16 | |
17 /** | |
18 * @author Jordi Boggiano <j.boggiano@seld.be> | |
19 */ | |
20 class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface | |
21 { | |
22 use SerializerAwareTrait; | |
23 | |
24 /** | |
25 * {@inheritdoc} | |
26 */ | |
27 public function normalize($object, $format = null, array $context = array()) | |
28 { | |
29 return $object->normalize($this->serializer, $format, $context); | |
30 } | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 public function denormalize($data, $class, $format = null, array $context = array()) | |
36 { | |
37 $object = new $class(); | |
38 $object->denormalize($this->serializer, $data, $format, $context); | |
39 | |
40 return $object; | |
41 } | |
42 | |
43 /** | |
44 * Checks if the given class implements the NormalizableInterface. | |
45 * | |
46 * @param mixed $data Data to normalize | |
47 * @param string $format The format being (de-)serialized from or into | |
48 * | |
49 * @return bool | |
50 */ | |
51 public function supportsNormalization($data, $format = null) | |
52 { | |
53 return $data instanceof NormalizableInterface; | |
54 } | |
55 | |
56 /** | |
57 * Checks if the given class implements the NormalizableInterface. | |
58 * | |
59 * @param mixed $data Data to denormalize from | |
60 * @param string $type The class to which the data should be denormalized | |
61 * @param string $format The format being deserialized from | |
62 * | |
63 * @return bool | |
64 */ | |
65 public function supportsDenormalization($data, $type, $format = null) | |
66 { | |
67 if (!class_exists($type)) { | |
68 return false; | |
69 } | |
70 | |
71 return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface'); | |
72 } | |
73 } |