@@ -33,11 +33,11 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
33
33
protected static $ graphNodeMap = [];
34
34
35
35
/**
36
- * The items contained in the collection .
36
+ * The fields contained in the node .
37
37
*
38
38
* @var array
39
39
*/
40
- protected $ items = [];
40
+ protected $ fields = [];
41
41
42
42
/**
43
43
* Init this Graph object.
@@ -46,7 +46,7 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
46
46
*/
47
47
public function __construct (array $ data = [])
48
48
{
49
- $ this ->items = $ this ->castItems ($ data );
49
+ $ this ->fields = $ this ->castFields ($ data );
50
50
}
51
51
52
52
/**
@@ -59,8 +59,8 @@ public function __construct(array $data = [])
59
59
*/
60
60
public function getField ($ name , $ default = null )
61
61
{
62
- if (isset ($ this ->items [$ name ])) {
63
- return $ this ->items [$ name ];
62
+ if (isset ($ this ->fields [$ name ])) {
63
+ return $ this ->fields [$ name ];
64
64
}
65
65
66
66
return $ default ;
@@ -73,21 +73,21 @@ public function getField($name, $default = null)
73
73
*/
74
74
public function getFieldNames ()
75
75
{
76
- return array_keys ($ this ->items );
76
+ return array_keys ($ this ->fields );
77
77
}
78
78
79
79
/**
80
- * Get all of the items in the collection .
80
+ * Get all of the fields in the node .
81
81
*
82
82
* @return array
83
83
*/
84
84
public function all ()
85
85
{
86
- return $ this ->items ;
86
+ return $ this ->fields ;
87
87
}
88
88
89
89
/**
90
- * Get the collection of items as a plain array.
90
+ * Get all fields as a plain array.
91
91
*
92
92
* @return array
93
93
*/
@@ -99,51 +99,51 @@ public function asArray()
99
99
}
100
100
101
101
return $ value ;
102
- }, $ this ->items );
102
+ }, $ this ->fields );
103
103
}
104
104
105
105
/**
106
- * Run a map over each of the items .
106
+ * Run a map over each field .
107
107
*
108
108
* @param \Closure $callback
109
109
*
110
110
* @return static
111
111
*/
112
112
public function map (\Closure $ callback )
113
113
{
114
- return new static (array_map ($ callback , $ this ->items , array_keys ($ this ->items )));
114
+ return new static (array_map ($ callback , $ this ->fields , array_keys ($ this ->fields )));
115
115
}
116
116
117
117
/**
118
- * Get the collection of items as JSON.
118
+ * Get all fields as JSON.
119
119
*
120
120
* @param int $options
121
121
*
122
122
* @return string
123
123
*/
124
124
public function asJson ($ options = 0 )
125
125
{
126
- return json_encode ($ this ->uncastItems (), $ options );
126
+ return json_encode ($ this ->uncastFields (), $ options );
127
127
}
128
128
129
129
/**
130
- * Count the number of items in the collection.
130
+ * Count the number of fields in the collection.
131
131
*
132
132
* @return int
133
133
*/
134
134
public function count ()
135
135
{
136
- return count ($ this ->items );
136
+ return count ($ this ->fields );
137
137
}
138
138
139
139
/**
140
- * Get an iterator for the items .
140
+ * Get an iterator for the fields .
141
141
*
142
142
* @return \ArrayIterator
143
143
*/
144
144
public function getIterator ()
145
145
{
146
- return new \ArrayIterator ($ this ->items );
146
+ return new \ArrayIterator ($ this ->fields );
147
147
}
148
148
149
149
/**
@@ -155,7 +155,7 @@ public function getIterator()
155
155
*/
156
156
public function offsetExists ($ key )
157
157
{
158
- return array_key_exists ($ key , $ this ->items );
158
+ return array_key_exists ($ key , $ this ->fields );
159
159
}
160
160
161
161
/**
@@ -167,7 +167,7 @@ public function offsetExists($key)
167
167
*/
168
168
public function offsetGet ($ key )
169
169
{
170
- return $ this ->items [$ key ];
170
+ return $ this ->fields [$ key ];
171
171
}
172
172
173
173
/**
@@ -181,9 +181,9 @@ public function offsetGet($key)
181
181
public function offsetSet ($ key , $ value )
182
182
{
183
183
if (is_null ($ key )) {
184
- $ this ->items [] = $ value ;
184
+ $ this ->fields [] = $ value ;
185
185
} else {
186
- $ this ->items [$ key ] = $ value ;
186
+ $ this ->fields [$ key ] = $ value ;
187
187
}
188
188
}
189
189
@@ -196,7 +196,7 @@ public function offsetSet($key, $value)
196
196
*/
197
197
public function offsetUnset ($ key )
198
198
{
199
- unset($ this ->items [$ key ]);
199
+ unset($ this ->fields [$ key ]);
200
200
}
201
201
202
202
/**
@@ -211,51 +211,51 @@ public function __toString()
211
211
212
212
/**
213
213
* Iterates over an array and detects the types each node
214
- * should be cast to and returns all the items as an array.
214
+ * should be cast to and returns all the fields as an array.
215
215
*
216
216
* @TODO Add auto-casting to AccessToken entities.
217
217
*
218
218
* @param array $data the array to iterate over
219
219
*
220
220
* @return array
221
221
*/
222
- public function castItems (array $ data )
222
+ public function castFields (array $ data )
223
223
{
224
- $ items = [];
224
+ $ fields = [];
225
225
226
226
foreach ($ data as $ k => $ v ) {
227
227
if ($ this ->shouldCastAsDateTime ($ k )
228
228
&& (is_numeric ($ v )
229
229
|| $ this ->isIso8601DateString ($ v ))
230
230
) {
231
- $ items [$ k ] = $ this ->castToDateTime ($ v );
231
+ $ fields [$ k ] = $ this ->castToDateTime ($ v );
232
232
} elseif ($ k === 'birthday ' ) {
233
- $ items [$ k ] = $ this ->castToBirthday ($ v );
233
+ $ fields [$ k ] = $ this ->castToBirthday ($ v );
234
234
} else {
235
- $ items [$ k ] = $ v ;
235
+ $ fields [$ k ] = $ v ;
236
236
}
237
237
}
238
238
239
- return $ items ;
239
+ return $ fields ;
240
240
}
241
241
242
242
/**
243
243
* Uncasts any auto-casted datatypes.
244
- * Basically the reverse of castItems ().
244
+ * Basically the reverse of castFields ().
245
245
*
246
246
* @return array
247
247
*/
248
- public function uncastItems ()
248
+ public function uncastFields ()
249
249
{
250
- $ items = $ this ->asArray ();
250
+ $ fields = $ this ->asArray ();
251
251
252
252
return array_map (function ($ v ) {
253
253
if ($ v instanceof \DateTime) {
254
254
return $ v ->format (\DateTime::ISO8601 );
255
255
}
256
256
257
257
return $ v ;
258
- }, $ items );
258
+ }, $ fields );
259
259
}
260
260
261
261
/**
0 commit comments