This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/*
2012-03-31 22:00:32 +01:00
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
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.
*/
namespace Symfony\Component\Serializer\Normalizer;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface
{
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null)
{
return $object->normalize($this->serializer, $format);
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null)
{
$object = new $class;
$object->denormalize($this->serializer, $data, $format);
2011-06-08 11:12:55 +01: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
*
* @return Boolean
*/
public function supportsNormalization($data, $format = null)
{
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
*
* @return Boolean
*/
public function supportsDenormalization($data, $type, $format = null)
{
$class = new \ReflectionClass($type);
return $class->isSubclassOf('Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
}
}