2525/**
2626 * @package Facebook
2727 */
28- class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
28+ class GraphNode
2929{
3030 /**
3131 * @var array maps object key names to Graph object types
@@ -37,7 +37,7 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
3737 *
3838 * @var array
3939 */
40- protected $ fields = [];
40+ private $ fields = [];
4141
4242 /**
4343 * Init this Graph object.
@@ -81,7 +81,7 @@ public function getFieldNames()
8181 *
8282 * @return array
8383 */
84- public function all ()
84+ public function getFields ()
8585 {
8686 return $ this ->fields ;
8787 }
@@ -103,110 +103,23 @@ public function asArray()
103103 }
104104
105105 /**
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.
121107 *
122108 * @return string
123109 */
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 ()
198111 {
199- unset ($ this ->fields [ $ key ] );
112+ return json_encode ($ this ->uncastFields () );
200113 }
201114
202115 /**
203- * Convert the collection to its string representation .
116+ * Getter for $graphNodeMap .
204117 *
205- * @return string
118+ * @return array
206119 */
207- public function __toString ()
120+ public static function getNodeMap ()
208121 {
209- return $ this -> asJson () ;
122+ return static :: $ graphNodeMap ;
210123 }
211124
212125 /**
@@ -219,7 +132,7 @@ public function __toString()
219132 *
220133 * @return array
221134 */
222- public function castFields (array $ data )
135+ private function castFields (array $ data )
223136 {
224137 $ fields = [];
225138
@@ -245,7 +158,7 @@ public function castFields(array $data)
245158 *
246159 * @return array
247160 */
248- public function uncastFields ()
161+ private function uncastFields ()
249162 {
250163 $ fields = $ this ->asArray ();
251164
@@ -258,6 +171,28 @@ public function uncastFields()
258171 }, $ fields );
259172 }
260173
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+
261196 /**
262197 * Detects an ISO 8601 formatted string.
263198 *
@@ -269,7 +204,7 @@ public function uncastFields()
269204 * @see http://www.cl.cam.ac.uk/~mgk25/iso-time.html
270205 * @see http://en.wikipedia.org/wiki/ISO_8601
271206 */
272- public function isIso8601DateString ($ string )
207+ private function isIso8601DateString ($ string )
273208 {
274209 // This insane regex was yoinked from here:
275210 // http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
@@ -285,36 +220,14 @@ public function isIso8601DateString($string)
285220 return preg_match ($ crazyInsaneRegexThatSomehowDetectsIso8601 , $ string ) === 1 ;
286221 }
287222
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-
310223 /**
311224 * Casts a date value from Graph to DateTime.
312225 *
313226 * @param int|string $value
314227 *
315228 * @return \DateTime
316229 */
317- public function castToDateTime ($ value )
230+ private function castToDateTime ($ value )
318231 {
319232 if (is_int ($ value )) {
320233 $ dt = new \DateTime ();
@@ -333,18 +246,8 @@ public function castToDateTime($value)
333246 *
334247 * @return Birthday
335248 */
336- public function castToBirthday ($ value )
249+ private function castToBirthday ($ value )
337250 {
338251 return new Birthday ($ value );
339252 }
340-
341- /**
342- * Getter for $graphNodeMap.
343- *
344- * @return array
345- */
346- public static function getNodeMap ()
347- {
348- return static ::$ graphNodeMap ;
349- }
350253}
0 commit comments