Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toml Laravel Package

internal/toml

PHP 8.1+ TOML 1.0/1.1 parser and encoder. Parse TOML into PHP arrays or an AST, modify and round-trip back to TOML. Simple static API (Toml::parse/parseToArray/encode) for config files and tooling.

View on GitHub
Deep Wiki
Context7

internal/toml is a TOML 1.0.0/1.1.0 parser and encoder for PHP 8.1+. It converts TOML documents into native PHP arrays and can encode PHP data structures back into clean TOML.

Beyond simple parsing, it also supports working with an AST (Abstract Syntax Tree) for inspection, modification, and reliable round-trip serialization.

  • Parse TOML to PHP arrays via Toml::parseToArray()
  • Encode arrays to TOML with Toml::encode()
  • AST-based parsing using Toml::parse() for node-level access
  • Serialize documents back to TOML by casting the document to string
  • Built for modern PHP with a straightforward, static API
Frequently asked questions about Toml
How do I parse a TOML config file in Laravel using internal/toml?
Use `Toml::parseToArray(file_get_contents('path/to/config.toml'))` to convert TOML into a PHP array. Store the result in Laravel’s config cache with `config(['toml-key' => $parsedArray])` or merge it into `config/app.php` via a service provider.
Does internal/toml support TOML 1.1 features like bare keys or table arrays?
Yes, the package fully supports TOML 1.1 (verified via spec compliance). It handles bare keys, dotted keys, table arrays, and other 1.1 features without breaking legacy TOML 1.0 files. Tested with real-world TOML from Terraform and Pulumi.
Can I use internal/toml to replace Laravel’s PHP config files with TOML?
Absolutely. Create a custom `ConfigReader` to load TOML files from `config/toml/` and merge them into Laravel’s config system. The package’s `parseToArray()` method outputs standard PHP arrays, so integration is seamless. Example: `config(['database' => Toml::parseToArray('config/toml/database.toml')])`.
How does internal/toml perform compared to spatie/toml or YAML parsers?
internal/toml is optimized for PHP 8.1+ and TOML 1.1, offering faster parsing for large configs (e.g., 10KB+) than YAML/JSON. Benchmark against `spatie/toml` (TOML 0.5.0) to confirm, but expect better performance for complex TOML structures like nested tables or arrays. AST-based parsing adds minimal overhead.
What’s the difference between `parseToArray()` and `parse()` in internal/toml?
`parseToArray()` directly converts TOML to a PHP array for simplicity, while `parse()` returns an AST (Abstract Syntax Tree) for advanced use cases like validation, transformation, or schema enforcement. Use AST when you need to inspect/modify TOML nodes before encoding back to TOML.
Can I use internal/toml with Laravel Forge or Envoyer for deployment configs?
Yes. Deploy TOML configs alongside PHP assets via Forge/Envoyer. Use `Toml::parseToArray()` in a service provider to load configs during deployment, or cache parsed TOML in Laravel’s cache drivers (e.g., `cache()->forever('toml:config', $parsedArray)`) for performance.
How do I validate TOML files before parsing in Laravel?
Use the AST (`Toml::parse()`) to validate TOML structure before conversion. Check for required keys, data types, or schema compliance by traversing nodes (e.g., `foreach ($document->nodes as $node)`). For strict validation, integrate with `symfony/yaml` or `webonyx/graphql-php` for schema enforcement.
Will internal/toml work with PHP 8.2 or later?
The package targets PHP 8.1+, but monitor updates for PHP 8.2+ compatibility. Test early in CI/CD pipelines. If issues arise, consider a polyfill or fallback to `spatie/toml` (though it lacks TOML 1.1 support). The maintainers track PHP version changes closely.
How can I round-trip TOML (parse → modify → encode) without losing formatting?
Use `Toml::parse()` to get an AST, modify nodes (e.g., update values or add tables), then cast the document to a string: `(string) $document`. This preserves TOML formatting (comments, trailing commas, hex/octal numbers) during round-trip serialization.
Are there alternatives to internal/toml for Laravel TOML support?
The main alternative is `spatie/toml`, but it only supports TOML 0.5.0 and lacks AST features. For TOML 1.1, `internal/toml` is the best choice. If you need YAML/JSON fallback, combine it with `symfony/yaml` or `league/commonmark` for hybrid config systems.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport