2011-01-18 19:17:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-31 22:00:32 +01:00
|
|
|
* This file is part of the Symfony package.
|
2011-01-18 19:17:24 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-18 19:17:24 +00:00
|
|
|
*
|
2012-03-31 22:00:32 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2011-01-18 19:17:24 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-02 04:52:14 +01:00
|
|
|
namespace Symfony\Component\Serializer\Normalizer;
|
|
|
|
|
2011-01-18 19:17:24 +00:00
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
2011-12-11 20:18:03 +00:00
|
|
|
class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface
|
2011-01-18 19:17:24 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-01-18 13:08:59 +00:00
|
|
|
public function normalize($object, $format = null, array $context = array())
|
2011-01-18 19:17:24 +00:00
|
|
|
{
|
2013-01-18 13:08:59 +00:00
|
|
|
return $object->normalize($this->serializer, $format, $context);
|
2011-01-18 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-01-18 13:08:59 +00:00
|
|
|
public function denormalize($data, $class, $format = null, array $context = array())
|
2011-01-18 19:17:24 +00:00
|
|
|
{
|
2014-02-11 07:51:18 +00:00
|
|
|
$object = new $class();
|
2013-01-18 13:08:59 +00:00
|
|
|
$object->denormalize($this->serializer, $data, $format, $context);
|
2011-06-08 11:12:55 +01:00
|
|
|
|
2011-01-18 19:17:24 +00:00
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given class implements the NormalizableInterface.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param mixed $data Data to normalize.
|
|
|
|
* @param string $format The format being (de-)serialized from or into.
|
2012-11-16 16:06:12 +00:00
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-01-18 19:17:24 +00:00
|
|
|
*/
|
2011-05-06 18:36:56 +01:00
|
|
|
public function supportsNormalization($data, $format = null)
|
2011-01-18 19:17:24 +00:00
|
|
|
{
|
2011-05-06 18:36:56 +01:00
|
|
|
return $data instanceof NormalizableInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given class implements the NormalizableInterface.
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param mixed $data Data to denormalize from.
|
|
|
|
* @param string $type The class to which the data should be denormalized.
|
|
|
|
* @param string $format The format being deserialized from.
|
2012-11-16 16:06:12 +00:00
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return bool
|
2011-05-06 18:36:56 +01:00
|
|
|
*/
|
|
|
|
public function supportsDenormalization($data, $type, $format = null)
|
|
|
|
{
|
2015-04-13 22:07:23 +01:00
|
|
|
if (!class_exists($type)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-16 13:42:15 +00:00
|
|
|
return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
|
2011-01-18 19:17:24 +00:00
|
|
|
}
|
|
|
|
}
|