1 | <?php |
||
25 | final class ActorNormalizer extends Normalizer |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 8 | public function normalize($object, $format = null, array $context = array()) |
|
31 | { |
||
32 | 8 | if (!$object instanceof Actor) { |
|
33 | return null; |
||
34 | } |
||
35 | |||
36 | 8 | $data = array(); |
|
37 | |||
38 | 8 | $this->normalizeInverseFunctionalIdentifier($object->getInverseFunctionalIdentifier(), $data); |
|
39 | |||
40 | 8 | if (null !== $name = $object->getName()) { |
|
41 | $data['name'] = $name; |
||
42 | } |
||
43 | |||
44 | 8 | if ($object instanceof Group) { |
|
45 | 1 | $data['member'] = array(); |
|
46 | |||
47 | 1 | foreach ($object->getMembers() as $member) { |
|
48 | 1 | $data['member'][] = $this->normalize($member); |
|
49 | } |
||
50 | |||
51 | 1 | $data['objectType'] = 'Group'; |
|
52 | } else { |
||
53 | 8 | $data['objectType'] = 'Agent'; |
|
54 | } |
||
55 | |||
56 | 8 | return $data; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 9 | public function supportsNormalization($data, $format = null) |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 9 | public function denormalize($data, $class, $format = null, array $context = array()) |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 10 | public function supportsDenormalization($data, $type, $format = null) |
|
93 | |||
94 | 8 | private function normalizeInverseFunctionalIdentifier(InverseFunctionalIdentifier $iri = null, &$data) |
|
95 | { |
||
96 | 8 | if (null === $iri) { |
|
97 | 1 | return; |
|
98 | } |
||
99 | |||
100 | 8 | if (null !== $mbox = $iri->getMbox()) { |
|
101 | 8 | $data['mbox'] = $mbox; |
|
102 | } |
||
103 | |||
104 | 8 | if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) { |
|
105 | $data['mbox_sha1sum'] = $mboxSha1Sum; |
||
106 | } |
||
107 | |||
108 | 8 | if (null !== $openId = $iri->getOpenId()) { |
|
109 | $data['openid'] = $openId; |
||
110 | } |
||
111 | |||
112 | 8 | if (null !== $account = $iri->getAccount()) { |
|
113 | 2 | $data['account'] = $this->normalizeAttribute($account); |
|
114 | } |
||
115 | 8 | } |
|
116 | |||
117 | 9 | private function denormalizeInverseFunctionalIdentifier($data, $format = null, array $context = array()) |
|
118 | { |
||
119 | 9 | if (isset($data['mbox'])) { |
|
120 | 9 | return InverseFunctionalIdentifier::withMbox($data['mbox']); |
|
121 | } |
||
122 | |||
123 | 2 | if (isset($data['mboxSha1Sum'])) { |
|
124 | return InverseFunctionalIdentifier::withMboxSha1Sum($data['mboxSha1Sum']); |
||
125 | } |
||
126 | |||
127 | 2 | if (isset($data['openid'])) { |
|
128 | return InverseFunctionalIdentifier::withOpenId($data['openid']); |
||
129 | } |
||
130 | |||
131 | 2 | if (isset($data['account'])) { |
|
132 | 2 | return InverseFunctionalIdentifier::withAccount($this->denormalizeAccount($data, $format, $context)); |
|
133 | } |
||
134 | 1 | } |
|
135 | |||
136 | 2 | private function denormalizeAccount($data, $format = null, array $context = array()) |
|
144 | |||
145 | 1 | private function denormalizeGroup(InverseFunctionalIdentifier $iri = null, $name, $data, $format = null, array $context = array()) |
|
157 | } |
||
158 |