- How do I install devium/toml in a PHP or Laravel project?
- Install it with Composer by running composer require devium/toml. The library is framework-agnostic, so it loads through Composer autoloading with no Laravel service provider or config publishing step required. Once installed you can use the parser and encoder classes directly in a service, command or job.
- How do I parse a TOML file into a PHP array?
- Read the file contents with file_get_contents() or Laravel's File facade, then pass the string to the parser to get a native PHP array back. From there you can validate the array against a schema and hydrate a DTO, pass it to a domain validator, or call Config::set(). Keeping the parse call behind a small loader service makes the implementation easy to swap later.
- Can I convert a PHP array back to a TOML string with devium/toml?
- Yes. Pass a PHP array to the encoder and it returns a valid TOML string you can write to disk with file_put_contents(). Encoding is the riskier direction, so verify that key order, numeric types and datetime values survive the trip before relying on it for generated manifests or config files.
- Does devium/toml support nested tables, arrays of tables and datetimes?
- The library handles nested tables, arrays of tables and the standard TOML value types, which covers typical documents such as pyproject.toml, Cargo.toml and static-site configs. Because TOML has sharp edges, run your own fixture files through both the decode and encode paths to confirm behaviour on dotted keys, inline tables and multiline strings.
- Which TOML spec version does devium/toml support?
- Check the README and release notes for the exact spec version the parser targets before you commit. If TOML 1.0 conformance matters to your feature, run the official toml-test suite against both the decode and encode paths as a short spike. A partial parser can throw on valid documents or fail silently, which users experience as a false 'your config is invalid' error.
- How does devium/toml handle malformed TOML input?
- The library returns clear errors for malformed input instead of handing back a half-parsed array, so you can catch the failure and surface a readable message. Wrap the call in a try/catch and treat the exception as invalid user input in your own validation layer. Confirm the exception message includes file, line and column information before you show it to end users.
- Does devium/toml work outside Laravel in plain PHP?
- Yes. It is framework-agnostic and has no Laravel dependency, so it works in any Composer-based PHP project, CLI tool, build script or CI job. That makes it a practical choice for reading externally dictated TOML configs in a standalone command rather than inside a framework app.
- Which PHP and Laravel versions is devium/toml compatible with?
- The PHP constraint and any required extensions are declared in the package's composer.json, so start there. Check that constraint against your Laravel version, then re-run your test suite after a Laravel major upgrade in case the dependency tree conflicts with the framework's polyfills or mbstring stack. Pin the version in composer.json so upgrades stay predictable.
- What are the alternatives to devium/toml for parsing TOML in PHP?
- yosymfony/toml is the most commonly cited PHP alternative, and a sidecar or non-PHP parser is also an option when TOML is only consumed by tooling. Because TOML parsing is a narrow, replaceable responsibility, wrapping whichever library you pick behind a small codec contract keeps a future swap cheap. Benchmark the alternatives against your real config files rather than toy examples.
- Is devium/toml actively maintained and safe to use in production?
- It is a small, single-purpose library with a low blast radius, but it has limited community adoption, so assume you inherit maintenance and pin the version with a fork contingency. It is not a good fit as your application's own config layer, where Laravel's PHP config files, env() and config caching already solve the problem. Use it as a leaf dependency inside features that genuinely need TOML interop, behind an abstraction.