-
Notifications
You must be signed in to change notification settings - Fork 125
/
BarNormalizer.php
44 lines (42 loc) · 1.81 KB
/
BarNormalizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Jane\OpenApi\Tests\Expected\Normalizer;
use Jane\JsonSchemaRuntime\Reference;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class BarNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
public function supportsDenormalization($data, $type, $format = null)
{
return $type === 'Jane\\OpenApi\\Tests\\Expected\\Model\\Bar';
}
public function supportsNormalization($data, $format = null)
{
return is_object($data) && get_class($data) === 'Jane\\OpenApi\\Tests\\Expected\\Model\\Bar';
}
public function denormalize($data, $class, $format = null, array $context = array())
{
if (!is_object($data)) {
throw new InvalidArgumentException(sprintf('Given $data is not an object (%s given). We need an object in order to continue denormalize method.', gettype($data)));
}
$object = new \Jane\OpenApi\Tests\Expected\Model\Bar();
if (property_exists($data, 'bar')) {
$object->setBar($data->{'bar'});
}
return $object;
}
public function normalize($object, $format = null, array $context = array())
{
$data = new \stdClass();
if (null !== $object->getBar()) {
$data->{'bar'} = $object->getBar();
}
return $data;
}
}