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