Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Normalizer/CustomNormalizer.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
17 /** | 17 /** |
18 * @author Jordi Boggiano <j.boggiano@seld.be> | 18 * @author Jordi Boggiano <j.boggiano@seld.be> |
19 */ | 19 */ |
20 class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface | 20 class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface |
21 { | 21 { |
22 use ObjectToPopulateTrait; | |
22 use SerializerAwareTrait; | 23 use SerializerAwareTrait; |
24 | |
25 private $cache = array(); | |
23 | 26 |
24 /** | 27 /** |
25 * {@inheritdoc} | 28 * {@inheritdoc} |
26 */ | 29 */ |
27 public function normalize($object, $format = null, array $context = array()) | 30 public function normalize($object, $format = null, array $context = array()) |
32 /** | 35 /** |
33 * {@inheritdoc} | 36 * {@inheritdoc} |
34 */ | 37 */ |
35 public function denormalize($data, $class, $format = null, array $context = array()) | 38 public function denormalize($data, $class, $format = null, array $context = array()) |
36 { | 39 { |
37 $object = new $class(); | 40 $object = $this->extractObjectToPopulate($class, $context) ?: new $class(); |
38 $object->denormalize($this->serializer, $data, $format, $context); | 41 $object->denormalize($this->serializer, $data, $format, $context); |
39 | 42 |
40 return $object; | 43 return $object; |
41 } | 44 } |
42 | 45 |
52 { | 55 { |
53 return $data instanceof NormalizableInterface; | 56 return $data instanceof NormalizableInterface; |
54 } | 57 } |
55 | 58 |
56 /** | 59 /** |
57 * Checks if the given class implements the NormalizableInterface. | 60 * Checks if the given class implements the DenormalizableInterface. |
58 * | 61 * |
59 * @param mixed $data Data to denormalize from | 62 * @param mixed $data Data to denormalize from |
60 * @param string $type The class to which the data should be denormalized | 63 * @param string $type The class to which the data should be denormalized |
61 * @param string $format The format being deserialized from | 64 * @param string $format The format being deserialized from |
62 * | 65 * |
63 * @return bool | 66 * @return bool |
64 */ | 67 */ |
65 public function supportsDenormalization($data, $type, $format = null) | 68 public function supportsDenormalization($data, $type, $format = null) |
66 { | 69 { |
67 if (!class_exists($type)) { | 70 if (isset($this->cache[$type])) { |
68 return false; | 71 return $this->cache[$type]; |
69 } | 72 } |
70 | 73 |
71 return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface'); | 74 if (!class_exists($type)) { |
75 return $this->cache[$type] = false; | |
76 } | |
77 | |
78 return $this->cache[$type] = is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface'); | |
72 } | 79 } |
73 } | 80 } |