1 | <?php |
||
25 | final class ActorNormalizer extends Normalizer |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 34 | public function normalize($object, $format = null, array $context = array()) |
|
31 | { |
||
32 | 34 | if (!$object instanceof Actor) { |
|
33 | return null; |
||
34 | } |
||
35 | |||
36 | 34 | $data = array(); |
|
37 | |||
38 | 34 | $this->normalizeInverseFunctionalIdentifier($object->getInverseFunctionalIdentifier(), $data); |
|
39 | |||
40 | 34 | if (null !== $name = $object->getName()) { |
|
41 | 10 | $data['name'] = $name; |
|
42 | } |
||
43 | |||
44 | 34 | if ($object instanceof Group) { |
|
45 | 21 | $members = array(); |
|
46 | |||
47 | 21 | foreach ($object->getMembers() as $member) { |
|
48 | 10 | $members[] = $this->normalize($member); |
|
49 | } |
||
50 | |||
51 | 21 | if (count($members) > 0) { |
|
52 | 10 | $data['member'] = $members; |
|
53 | } |
||
54 | |||
55 | 21 | $data['objectType'] = 'Group'; |
|
56 | } else { |
||
57 | 24 | $data['objectType'] = 'Agent'; |
|
58 | } |
||
59 | |||
60 | 34 | return $data; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 76 | public function supportsNormalization($data, $format = null) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 36 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 78 | public function supportsDenormalization($data, $type, $format = null) |
|
97 | |||
98 | 34 | private function normalizeInverseFunctionalIdentifier(InverseFunctionalIdentifier $iri = null, &$data) |
|
99 | { |
||
100 | 34 | if (null === $iri) { |
|
101 | return; |
||
102 | } |
||
103 | |||
104 | 34 | if (null !== $mbox = $iri->getMbox()) { |
|
105 | 25 | $data['mbox'] = $mbox; |
|
106 | } |
||
107 | |||
108 | 34 | if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) { |
|
109 | 5 | $data['mbox_sha1sum'] = $mboxSha1Sum; |
|
110 | } |
||
111 | |||
112 | 34 | if (null !== $openId = $iri->getOpenId()) { |
|
113 | 5 | $data['openid'] = $openId; |
|
114 | } |
||
115 | |||
116 | 34 | if (null !== $account = $iri->getAccount()) { |
|
117 | 6 | $data['account'] = $this->normalizeAttribute($account); |
|
118 | } |
||
119 | 34 | } |
|
120 | |||
121 | 36 | private function denormalizeInverseFunctionalIdentifier($data, $format = null, array $context = array()) |
|
122 | { |
||
123 | 36 | if (isset($data['mbox'])) { |
|
124 | 27 | return InverseFunctionalIdentifier::withMbox($data['mbox']); |
|
125 | } |
||
126 | |||
127 | 16 | if (isset($data['mbox_sha1sum'])) { |
|
128 | 5 | return InverseFunctionalIdentifier::withMboxSha1Sum($data['mbox_sha1sum']); |
|
129 | } |
||
130 | |||
131 | 11 | if (isset($data['openid'])) { |
|
132 | 5 | return InverseFunctionalIdentifier::withOpenId($data['openid']); |
|
133 | } |
||
134 | |||
135 | 6 | if (isset($data['account'])) { |
|
136 | 6 | return InverseFunctionalIdentifier::withAccount($this->denormalizeAccount($data, $format, $context)); |
|
137 | } |
||
138 | } |
||
139 | |||
140 | 6 | private function denormalizeAccount($data, $format = null, array $context = array()) |
|
148 | |||
149 | 21 | private function denormalizeGroup(InverseFunctionalIdentifier $iri = null, $name, $data, $format = null, array $context = array()) |
|
161 | } |
||
162 |