1: <?php
2:
3: namespace SellerLabs\Snagshout\Normalizer;
4:
5: use Joli\Jane\Runtime\Reference;
6: use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7: use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
8: use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
9: class ShippingNormalizer extends SerializerAwareNormalizer implements DenormalizerInterface, NormalizerInterface
10: {
11: public function supportsDenormalization($data, $type, $format = null)
12: {
13: if ($type !== 'SellerLabs\\Snagshout\\Model\\Shipping') {
14: return false;
15: }
16: return true;
17: }
18: public function supportsNormalization($data, $format = null)
19: {
20: if ($data instanceof \SellerLabs\Snagshout\Model\Shipping) {
21: return true;
22: }
23: return false;
24: }
25: public function denormalize($data, $class, $format = null, array $context = array())
26: {
27: $object = new \SellerLabs\Snagshout\Model\Shipping();
28: if (property_exists($data, 'note')) {
29: $object->setNote($data->{'note'});
30: }
31: if (property_exists($data, 'price')) {
32: $object->setPrice($data->{'price'});
33: }
34: if (property_exists($data, 'id')) {
35: $object->setId($data->{'id'});
36: }
37: if (property_exists($data, 'daysMin')) {
38: $object->setDaysMin($data->{'daysMin'});
39: }
40: if (property_exists($data, 'daysMax')) {
41: $object->setDaysMax($data->{'daysMax'});
42: }
43: return $object;
44: }
45: public function normalize($object, $format = null, array $context = array())
46: {
47: $data = new \stdClass();
48: if (null !== $object->getNote()) {
49: $data->{'note'} = $object->getNote();
50: }
51: if (null !== $object->getPrice()) {
52: $data->{'price'} = $object->getPrice();
53: }
54: if (null !== $object->getId()) {
55: $data->{'id'} = $object->getId();
56: }
57: if (null !== $object->getDaysMin()) {
58: $data->{'daysMin'} = $object->getDaysMin();
59: }
60: if (null !== $object->getDaysMax()) {
61: $data->{'daysMax'} = $object->getDaysMax();
62: }
63: return $data;
64: }
65: }