-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUserModelNormalizer.php
More file actions
executable file
·61 lines (54 loc) · 1.8 KB
/
UserModelNormalizer.php
File metadata and controls
executable file
·61 lines (54 loc) · 1.8 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace SmartCat\Client\Normalizer;
class UserModelNormalizer extends AbstractNormalizer
{
public function supportsDenormalization($data, $type, $format = null)
{
if ($type !== 'SmartCat\\Client\\Model\\UserModel') {
return false;
}
return true;
}
public function supportsNormalization($data, $format = null)
{
if ($data instanceof \SmartCat\Client\Model\UserModel) {
return true;
}
return false;
}
public function denormalize($data, $class, $format = null, array $context = array())
{
$object = new \SmartCat\Client\Model\UserModel();
$data = (array) $data;
$properties = ['id', 'externalId', 'email', 'firstName', 'lastName', 'rightsGroup'];
foreach ($properties as $property) {
if (isset($data[$property])) {
$object->{'set' . ucfirst($property)}($data[$property]);
}
}
return $object;
}
public function normalize($object, $format = null, array $context = array())
{
$data = new \stdClass();
if (null !== $object->getId()) {
$data->{'id'} = $object->getId();
}
if (null !== $object->getExternalId()) {
$data->{'externalId'} = $object->getExternalId();
}
if (null !== $object->getEmail()) {
$data->{'email'} = $object->getEmail();
}
if (null !== $object->getFirstName()) {
$data->{'firstName'} = $object->getFirstName();
}
if (null !== $object->getLastName()) {
$data->{'lastName'} = $object->getLastName();
}
if (null !== $object->getRightsGroup()) {
$data->{'rightsGroup'} = $object->getRightsGroup();
}
return $data;
}
}