Skip to content

Add ArrayStyle encoder option for multiline arrays#20

Merged
dereuromark merged 1 commit into
masterfrom
add-array-style-option
Mar 30, 2026
Merged

Add ArrayStyle encoder option for multiline arrays#20
dereuromark merged 1 commit into
masterfrom
add-array-style-option

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

Adds new encoder options for controlling array formatting, useful for better git diffs and readability.

New Options

Option Type Default Description
arrayStyle ArrayStyle Inline Array formatting style
arrayAutoThreshold int 3 Item count threshold for Auto mode
indent string ' ' Indentation for multiline arrays

ArrayStyle Enum

  • ArrayStyle::Inline - Single line (existing behavior): [1, 2, 3]
  • ArrayStyle::Multiline - One item per line with indentation
  • ArrayStyle::Auto - Multiline when items exceed threshold

Examples

// Inline (default)
Toml::encode(['ports' => [8080, 8081, 8082]]);
// ports = [8080, 8081, 8082]

// Multiline
Toml::encode(
    ['ports' => [8080, 8081, 8082]],
    new EncoderOptions(arrayStyle: ArrayStyle::Multiline),
);
// ports = [
//     8080,
//     8081,
//     8082,
// ]

// Auto (multiline when > 3 items)
Toml::encode(
    ['ports' => [8080, 8081, 8082, 8083, 8084]],
    new EncoderOptions(arrayStyle: ArrayStyle::Auto, arrayAutoThreshold: 3),
);
// ports = [
//     8080,
//     8081,
//     8082,
//     8083,
//     8084,
// ]

Documentation

Also updates API documentation with complete EncoderOptions reference including previously undocumented options (integerGrouping, trailingComma, dottedKeys).

Add new encoder options for array formatting:
- `arrayStyle`: Controls array output format
  - `ArrayStyle::Inline`: Single line (default, existing behavior)
  - `ArrayStyle::Multiline`: One item per line with indentation
  - `ArrayStyle::Auto`: Multiline when items exceed threshold
- `arrayAutoThreshold`: Item count threshold for Auto mode (default: 3)
- `indent`: Indentation string for multiline arrays (default: 4 spaces)

Also updates API documentation with complete EncoderOptions reference
including previously undocumented options (integerGrouping, trailingComma,
dottedKeys).
@dereuromark dereuromark merged commit 4ec65a3 into master Mar 30, 2026
3 checks passed
@dereuromark dereuromark deleted the add-array-style-option branch March 30, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant