35 $pk = OrmUtils::getFirstKeyValue ( $o );
36 $classname = get_class ( $o );
38 $r = [
'id' => $pk,
'type' => $frontClassname ];
39 $r [
'attributes'] = $o->_rest;
40 $fieldsInRelations = OrmUtils::getRelationInfos ( $classname );
44 foreach ( $o as $k => $v ) {
45 if (isset ( $fieldsInRelations [$k] )) {
46 $rClassname = $fieldsInRelations [$k] [
'className'] ?? $fieldsInRelations [$k] [
'targetEntity'];
48 $member = $fieldsInRelations [$k] [
'member'] ?? $k;
49 if (isset ( $v->_rest )) {
50 $pkf = OrmUtils::getFirstKey ( $rClassname );
51 $r [
'relationships'] [$member] [
'data'] = [
'id' => $v->_rest [$pkf],
'type' => $rFrontClassname ];
53 } elseif (\is_array ( $v )) {
54 foreach ( $v as $index => $value ) {
55 if (isset ( $value->_rest )) {
58 $pkf = OrmUtils::getFirstKey ( $rClassname );
59 $r [
'relationships'] [$member] [
'data'] [] = [
'id' => $value->_rest [$pkf],
'type' => $rFrontClassname ];
63 $r [
'relationships'] [$member] [
'data'] = [
'id' => $v,
'type' => $rFrontClassname ];
68 unset ( $r [
'attributes'] [$member] );
69 unset ( $r [
'attributes'] [$k] );
72 unset ( $r [
'attributes'] [
'id'] );
73 unset ( $r [
'attributes'] [
'_rest'] );
97 $r [
'relationships'] [$member] [
'links'] = [ $this->
getLink ( $this->relationLink, [
"baseRoute" => $this->baseRoute,
'id' => $pk,
'member' => $member,
'classname' => $frontClassname ] ),$this->
getLink ( $this->selfLink, [
"baseRoute" => $this->baseRoute,
'id' => $pkMember,
'classname' => $rFrontClassname ] ) ];