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}
|
|
|
|
*/
|
2011-05-09 12:59:54 +01:00
|
|
|
public function normalize($object, $format = null)
|
2011-01-18 19:17:24 +00:00
|
|
|
{
|
2011-05-09 12:59:54 +01:00
|
|
|
return $object->normalize($this->serializer, $format);
|
2011-01-18 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function denormalize($data, $class, $format = null)
|
|
|
|
{
|
|
|
|
$object = new $class;
|
2011-05-09 12:59:54 +01:00
|
|
|
$object->denormalize($this->serializer, $data, $format);
|
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
|
|
|
*
|
2011-01-18 19:17:24 +00:00
|
|
|
* @return Boolean
|
|
|
|
*/
|
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
|
|
|
*
|
2011-05-06 18:36:56 +01:00
|
|
|
* @return Boolean
|
|
|
|
*/
|
|
|
|
public function supportsDenormalization($data, $type, $format = null)
|
|
|
|
{
|
|
|
|
$class = new \ReflectionClass($type);
|
|
|
|
|
2012-05-11 09:16:14 +01:00
|
|
|
return $class->isSubclassOf('Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
|
2011-01-18 19:17:24 +00:00
|
|
|
}
|
|
|
|
}
|