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 CampaignNormalizer extends SerializerAwareNormalizer implements DenormalizerInterface, NormalizerInterface
10: {
11: public function supportsDenormalization($data, $type, $format = null)
12: {
13: if ($type !== 'SellerLabs\\Snagshout\\Model\\Campaign') {
14: return false;
15: }
16: return true;
17: }
18: public function supportsNormalization($data, $format = null)
19: {
20: if ($data instanceof \SellerLabs\Snagshout\Model\Campaign) {
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\Campaign();
28: if (property_exists($data, 'id')) {
29: $object->setId($data->{'id'});
30: }
31: if (property_exists($data, 'name')) {
32: $object->setName($data->{'name'});
33: }
34: if (property_exists($data, 'description')) {
35: $object->setDescription($data->{'description'});
36: }
37: if (property_exists($data, 'note')) {
38: $object->setNote($data->{'note'});
39: }
40: if (property_exists($data, 'country')) {
41: $object->setCountry($data->{'country'});
42: }
43: if (property_exists($data, 'shoutChannels')) {
44: $values = array();
45: foreach ($data->{'shoutChannels'} as $value) {
46: $values[] = $value;
47: }
48: $object->setShoutChannels($values);
49: }
50: if (property_exists($data, 'url')) {
51: $object->setUrl($data->{'url'});
52: }
53: if (property_exists($data, 'shortUrl')) {
54: $object->setShortUrl($data->{'shortUrl'});
55: }
56: if (property_exists($data, 'availability')) {
57: $object->setAvailability($data->{'availability'});
58: }
59: if (property_exists($data, 'startsAt')) {
60: $object->setStartsAt($data->{'startsAt'});
61: }
62: if (property_exists($data, 'endsAt')) {
63: $object->setEndsAt($data->{'endsAt'});
64: }
65: if (property_exists($data, 'type')) {
66: $object->setType($data->{'type'});
67: }
68: if (property_exists($data, 'product')) {
69: $object->setProduct($this->serializer->deserialize($data->{'product'}, 'SellerLabs\\Snagshout\\Model\\Product', 'raw', $context));
70: }
71: if (property_exists($data, 'promotions')) {
72: $values_1 = array();
73: foreach ($data->{'promotions'} as $value_1) {
74: $values_1[] = $this->serializer->deserialize($value_1, 'SellerLabs\\Snagshout\\Model\\Promotion', 'raw', $context);
75: }
76: $object->setPromotions($values_1);
77: }
78: return $object;
79: }
80: public function normalize($object, $format = null, array $context = array())
81: {
82: $data = new \stdClass();
83: if (null !== $object->getId()) {
84: $data->{'id'} = $object->getId();
85: }
86: if (null !== $object->getName()) {
87: $data->{'name'} = $object->getName();
88: }
89: if (null !== $object->getDescription()) {
90: $data->{'description'} = $object->getDescription();
91: }
92: if (null !== $object->getNote()) {
93: $data->{'note'} = $object->getNote();
94: }
95: if (null !== $object->getCountry()) {
96: $data->{'country'} = $object->getCountry();
97: }
98: if (null !== $object->getShoutChannels()) {
99: $values = array();
100: foreach ($object->getShoutChannels() as $value) {
101: $values[] = $value;
102: }
103: $data->{'shoutChannels'} = $values;
104: }
105: if (null !== $object->getUrl()) {
106: $data->{'url'} = $object->getUrl();
107: }
108: if (null !== $object->getShortUrl()) {
109: $data->{'shortUrl'} = $object->getShortUrl();
110: }
111: if (null !== $object->getAvailability()) {
112: $data->{'availability'} = $object->getAvailability();
113: }
114: if (null !== $object->getStartsAt()) {
115: $data->{'startsAt'} = $object->getStartsAt();
116: }
117: if (null !== $object->getEndsAt()) {
118: $data->{'endsAt'} = $object->getEndsAt();
119: }
120: if (null !== $object->getType()) {
121: $data->{'type'} = $object->getType();
122: }
123: if (null !== $object->getProduct()) {
124: $data->{'product'} = $this->serializer->serialize($object->getProduct(), 'raw', $context);
125: }
126: if (null !== $object->getPromotions()) {
127: $values_1 = array();
128: foreach ($object->getPromotions() as $value_1) {
129: $values_1[] = $this->serializer->serialize($value_1, 'raw', $context);
130: }
131: $data->{'promotions'} = $values_1;
132: }
133: return $data;
134: }
135: }