25
25
/**
26
26
* @package Facebook
27
27
*/
28
- class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
28
+ class GraphNode
29
29
{
30
30
/**
31
31
* @var array maps object key names to Graph object types
@@ -37,7 +37,7 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
37
37
*
38
38
* @var array
39
39
*/
40
- protected $ fields = [];
40
+ private $ fields = [];
41
41
42
42
/**
43
43
* Init this Graph object.
@@ -81,7 +81,7 @@ public function getFieldNames()
81
81
*
82
82
* @return array
83
83
*/
84
- public function all ()
84
+ public function getFields ()
85
85
{
86
86
return $ this ->fields ;
87
87
}
@@ -103,110 +103,23 @@ public function asArray()
103
103
}
104
104
105
105
/**
106
- * Run a map over each field.
107
- *
108
- * @param \Closure $callback
109
- *
110
- * @return static
111
- */
112
- public function map (\Closure $ callback )
113
- {
114
- return new static (array_map ($ callback , $ this ->fields , array_keys ($ this ->fields )));
115
- }
116
-
117
- /**
118
- * Get all fields as JSON.
119
- *
120
- * @param int $options
106
+ * Convert the collection to its string representation.
121
107
*
122
108
* @return string
123
109
*/
124
- public function asJson ($ options = 0 )
125
- {
126
- return json_encode ($ this ->uncastFields (), $ options );
127
- }
128
-
129
- /**
130
- * Count the number of fields in the collection.
131
- *
132
- * @return int
133
- */
134
- public function count ()
135
- {
136
- return count ($ this ->fields );
137
- }
138
-
139
- /**
140
- * Get an iterator for the fields.
141
- *
142
- * @return \ArrayIterator
143
- */
144
- public function getIterator ()
145
- {
146
- return new \ArrayIterator ($ this ->fields );
147
- }
148
-
149
- /**
150
- * Determine if an item exists at an offset.
151
- *
152
- * @param mixed $key
153
- *
154
- * @return bool
155
- */
156
- public function offsetExists ($ key )
157
- {
158
- return array_key_exists ($ key , $ this ->fields );
159
- }
160
-
161
- /**
162
- * Get an item at a given offset.
163
- *
164
- * @param mixed $key
165
- *
166
- * @return mixed
167
- */
168
- public function offsetGet ($ key )
169
- {
170
- return $ this ->fields [$ key ];
171
- }
172
-
173
- /**
174
- * Set the item at a given offset.
175
- *
176
- * @param mixed $key
177
- * @param mixed $value
178
- *
179
- * @return void
180
- */
181
- public function offsetSet ($ key , $ value )
182
- {
183
- if (is_null ($ key )) {
184
- $ this ->fields [] = $ value ;
185
- } else {
186
- $ this ->fields [$ key ] = $ value ;
187
- }
188
- }
189
-
190
- /**
191
- * Unset the item at a given offset.
192
- *
193
- * @param string $key
194
- *
195
- * @return void
196
- */
197
- public function offsetUnset ($ key )
110
+ public function __toString ()
198
111
{
199
- unset ($ this ->fields [ $ key ] );
112
+ return json_encode ($ this ->uncastFields () );
200
113
}
201
114
202
115
/**
203
- * Convert the collection to its string representation .
116
+ * Getter for $graphNodeMap .
204
117
*
205
- * @return string
118
+ * @return array
206
119
*/
207
- public function __toString ()
120
+ public static function getNodeMap ()
208
121
{
209
- return $ this -> asJson () ;
122
+ return static :: $ graphNodeMap ;
210
123
}
211
124
212
125
/**
@@ -219,7 +132,7 @@ public function __toString()
219
132
*
220
133
* @return array
221
134
*/
222
- public function castFields (array $ data )
135
+ private function castFields (array $ data )
223
136
{
224
137
$ fields = [];
225
138
@@ -245,7 +158,7 @@ public function castFields(array $data)
245
158
*
246
159
* @return array
247
160
*/
248
- public function uncastFields ()
161
+ private function uncastFields ()
249
162
{
250
163
$ fields = $ this ->asArray ();
251
164
@@ -258,6 +171,28 @@ public function uncastFields()
258
171
}, $ fields );
259
172
}
260
173
174
+ /**
175
+ * Determines if a value from Graph should be cast to DateTime.
176
+ *
177
+ * @param string $key
178
+ *
179
+ * @return bool
180
+ */
181
+ private function shouldCastAsDateTime ($ key )
182
+ {
183
+ return in_array ($ key , [
184
+ 'created_time ' ,
185
+ 'updated_time ' ,
186
+ 'start_time ' ,
187
+ 'stop_time ' ,
188
+ 'end_time ' ,
189
+ 'backdated_time ' ,
190
+ 'issued_at ' ,
191
+ 'expires_at ' ,
192
+ 'publish_time '
193
+ ], true );
194
+ }
195
+
261
196
/**
262
197
* Detects an ISO 8601 formatted string.
263
198
*
@@ -269,7 +204,7 @@ public function uncastFields()
269
204
* @see http://www.cl.cam.ac.uk/~mgk25/iso-time.html
270
205
* @see http://en.wikipedia.org/wiki/ISO_8601
271
206
*/
272
- public function isIso8601DateString ($ string )
207
+ private function isIso8601DateString ($ string )
273
208
{
274
209
// This insane regex was yoinked from here:
275
210
// http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
@@ -285,36 +220,14 @@ public function isIso8601DateString($string)
285
220
return preg_match ($ crazyInsaneRegexThatSomehowDetectsIso8601 , $ string ) === 1 ;
286
221
}
287
222
288
- /**
289
- * Determines if a value from Graph should be cast to DateTime.
290
- *
291
- * @param string $key
292
- *
293
- * @return bool
294
- */
295
- public function shouldCastAsDateTime ($ key )
296
- {
297
- return in_array ($ key , [
298
- 'created_time ' ,
299
- 'updated_time ' ,
300
- 'start_time ' ,
301
- 'stop_time ' ,
302
- 'end_time ' ,
303
- 'backdated_time ' ,
304
- 'issued_at ' ,
305
- 'expires_at ' ,
306
- 'publish_time '
307
- ], true );
308
- }
309
-
310
223
/**
311
224
* Casts a date value from Graph to DateTime.
312
225
*
313
226
* @param int|string $value
314
227
*
315
228
* @return \DateTime
316
229
*/
317
- public function castToDateTime ($ value )
230
+ private function castToDateTime ($ value )
318
231
{
319
232
if (is_int ($ value )) {
320
233
$ dt = new \DateTime ();
@@ -333,18 +246,8 @@ public function castToDateTime($value)
333
246
*
334
247
* @return Birthday
335
248
*/
336
- public function castToBirthday ($ value )
249
+ private function castToBirthday ($ value )
337
250
{
338
251
return new Birthday ($ value );
339
252
}
340
-
341
- /**
342
- * Getter for $graphNodeMap.
343
- *
344
- * @return array
345
- */
346
- public static function getNodeMap ()
347
- {
348
- return static ::$ graphNodeMap ;
349
- }
350
253
}
0 commit comments