doSerialize( $expData ) + [ 'serializer' => __CLASS__, 'version' => 0.1 ]; } private function doSerialize( $expData ) { $serialization = [ 'subject' => $expData->getSubject()->getSerialization() ]; $properties = []; foreach ( $expData->getProperties() as $property ) { $properties[$property->getUri()] = [ 'property' => $property->getSerialization(), 'children' => $this->doSerializeChildren( $expData->getValues( $property ) ) ]; } return $serialization + [ 'data' => $properties ]; } private function doSerializeChildren( array $elements ) { $children = []; if ( $elements === [] ) { return $children; } foreach ( $elements as $element ) { $children[] = $element instanceof ExpElement ? $element->getSerialization() : $this->doSerialize( $element ); } return $children; } }