,numericTokens:string[],fieldValues:array} */ protected function composeFieldContext( array $ordered_refs, callable $resolve, callable $label ): array { $lines = array(); $facts = array(); $field_values = array(); foreach ( $ordered_refs as $ref ) { $resolved = call_user_func( $resolve, $ref ); $field_values[ $ref ] = $resolved; if ( 'pairs' === ( $resolved['type'] ?? '' ) ) { foreach ( (array) $resolved['value'] as $pair ) { $pair_label = is_array( $pair ) ? (string) ( $pair['label'] ?? '' ) : ''; $pair_value = is_array( $pair ) ? (string) ( $pair['value'] ?? '' ) : ''; if ( '' === $pair_label || '' === $pair_value ) { continue; } $lines[] = $pair_label . ': ' . $pair_value; $facts[] = array( 'label' => $pair_label, 'value' => $pair_value ); } continue; } if ( ! empty( $resolved['empty'] ) ) { continue; } $ref_label = (string) call_user_func( $label, $ref ); $value = 'list' === ( $resolved['type'] ?? '' ) ? implode( ', ', array_map( 'strval', (array) $resolved['value'] ) ) : (string) $resolved['value']; if ( '' === $value ) { continue; } $lines[] = $ref_label . ': ' . $value; $facts[] = array( 'label' => $ref_label, 'value' => $value ); } $text = implode( "\n", $lines ); return array( 'text' => $text, 'facts' => $facts, 'numericTokens' => TextMetrics::numericTokens( $text ), 'fieldValues' => $field_values, ); } }