-
Notifications
You must be signed in to change notification settings - Fork 125
/
BazBazNormalizer.php
44 lines (42 loc) · 1.81 KB
/
BazBazNormalizer.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\JsonSchema\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 BazBazNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
public function supportsDenormalization($data, $type, $format = null)
{
return $type === 'Jane\\JsonSchema\\Tests\\Expected\\Model\\BazBaz';
}
public function supportsNormalization($data, $format = null)
{
return $data instanceof \Jane\JsonSchema\Tests\Expected\Model\BazBaz;
}
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\JsonSchema\Tests\Expected\Model\BazBaz();
if (property_exists($data, 'baz')) {
$object->setBaz($data->{'baz'});
}
return $object;
}
public function normalize($object, $format = null, array $context = array())
{
$data = new \stdClass();
if (null !== $object->getBaz()) {
$data->{'baz'} = $object->getBaz();
}
return $data;
}
}