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

74 lines
2.0 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;
2016-01-26 12:57:16 +00:00
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerAwareTrait;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
2016-01-26 12:57:16 +00:00
class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
{
2016-01-26 12:57:16 +00:00
use SerializerAwareTrait;
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = array())
{
return $object->normalize($this->serializer, $format, $context);
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
2014-02-11 07:51:18 +00:00
$object = new $class();
$object->denormalize($this->serializer, $data, $format, $context);
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
*
2014-04-16 11:30:19 +01:00
* @return bool
*/
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
*
2014-04-16 11:30:19 +01:00
* @return bool
*/
public function supportsDenormalization($data, $type, $format = null)
{
2015-04-13 22:07:23 +01:00
if (!class_exists($type)) {
return false;
}
return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
}
}