*/
class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
{
+ use ObjectToPopulateTrait;
use SerializerAwareTrait;
+ private $cache = array();
+
/**
* {@inheritdoc}
*/
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
- $object = new $class();
+ $object = $this->extractObjectToPopulate($class, $context) ?: new $class();
$object->denormalize($this->serializer, $data, $format, $context);
return $object;
}
/**
- * Checks if the given class implements the NormalizableInterface.
+ * Checks if the given class implements the DenormalizableInterface.
*
* @param mixed $data Data to denormalize from
* @param string $type The class to which the data should be denormalized
*/
public function supportsDenormalization($data, $type, $format = null)
{
+ if (isset($this->cache[$type])) {
+ return $this->cache[$type];
+ }
+
if (!class_exists($type)) {
- return false;
+ return $this->cache[$type] = false;
}
- return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
+ return $this->cache[$type] = is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
}
}