@@ -35,24 +35,23 @@ protected function parse(mixed $object): void
35
35
throw new ValidationException ('A Relationship object MUST contain at least one of the following properties: links, data, meta ' );
36
36
}
37
37
38
- if (property_exists ($ object , 'data ' )) {
39
- if ($ object ->data === null ) {
40
- $ this ->set ('data ' , $ object ->data );
41
- } elseif (is_array ($ object ->data )) {
42
- $ this ->set ('data ' , $ this ->create ('ResourceIdentifierCollection ' , $ object ->data ));
38
+ foreach (get_object_vars ($ object ) as $ key => $ value ) {
39
+ if ($ key === 'data ' ) {
40
+ if ($ value === null ) {
41
+ $ this ->set ('data ' , $ value );
42
+ } elseif (is_array ($ value )) {
43
+ $ this ->set ('data ' , $ this ->create ('ResourceIdentifierCollection ' , $ value ));
44
+ } else {
45
+ $ this ->set ('data ' , $ this ->create ('ResourceIdentifier ' , $ value ));
46
+ }
47
+ } elseif ($ key === 'meta ' ) {
48
+ $ this ->set ('meta ' , $ this ->create ('Meta ' , $ value ));
49
+ } elseif ($ key === 'links ' ) {
50
+ $ this ->set ('links ' , $ this ->create ('RelationshipLink ' , $ value ));
43
51
} else {
44
- $ this ->set (' data ' , $ this -> create ( ' ResourceIdentifier ' , $ object -> data ) );
52
+ $ this ->set ($ key , $ value );
45
53
}
46
54
}
47
-
48
- if (property_exists ($ object , 'meta ' )) {
49
- $ this ->set ('meta ' , $ this ->create ('Meta ' , $ object ->meta ));
50
- }
51
-
52
- // Parse 'links' after 'data'
53
- if (property_exists ($ object , 'links ' )) {
54
- $ this ->set ('links ' , $ this ->create ('RelationshipLink ' , $ object ->links ));
55
- }
56
55
}
57
56
58
57
/**
0 commit comments