@@ -116,37 +116,34 @@ public function toArrayWithProperties(array $properties): array
116116 */
117117 public function getPropertyValueAsSimple (string $ property )
118118 {
119- if ($ this ->$ property instanceof DomainObject) {
119+ $ value = $ this ->$ property ;
120+
121+ if ($ value instanceof DomainObject) {
120122 // Simple recursion for child DO's
121- return $ this -> $ property ->toArray ();
123+ return $ value ->toArray ();
122124 }
123125
124- if ($ this ->propertyIsTraversable ($ property )) {
126+ if ($ value instanceof \stdClass) {
127+ $ value = (array ) $ value ;
128+ }
129+ if (is_iterable ($ value )) {
125130 // Property is traversable
126- $ value = [];
131+ $ newValue = [];
127132
128133 // Traverse the
129- foreach ($ this -> $ property as $ childKey => $ childValue ) {
134+ foreach ($ value as $ childKey => $ childValue ) {
130135 if ($ childValue instanceof DomainObject) {
131- $ value [$ childKey ] = $ childValue ->toArray ();
136+ $ newValue [$ childKey ] = $ childValue ->toArray ();
132137 } else {
133- $ value [$ childKey ] = $ childValue ;
138+ $ newValue [$ childKey ] = $ childValue ;
134139 }
135140 }
136141
137- return $ value ;
142+ return $ newValue ;
138143 }
139144
140145 // All other properties are returned as is
141- return $ this ->$ property ;
142- }
143-
144- /**
145- * Is a property traversable?
146- */
147- public function propertyIsTraversable (string $ property ): bool
148- {
149- return is_iterable ($ this ->$ property ) || $ this ->$ property instanceof \stdClass;
146+ return $ value ;
150147 }
151148
152149 /**
0 commit comments