hypnotox / toml
A PHP package implementing a TOML file loader.
v1.0.1
2026-03-28 13:13 UTC
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.90
- phpunit/phpunit: ^11.0
- symfony/var-dumper: ^7.0
- vimeo/psalm: ^6.0
README
A PHP package for encoding and decoding TOML with immutable object representation.
Fully supports the TOML v1.0.0 specification and passes the toml-test conformance suite (678 decoder tests + 205 encoder tests).
Requires PHP 8.3+.
Installation
composer require hypnotox/toml
Usage
Decoding TOML
use HypnoTox\Toml\TomlFactory; $factory = new TomlFactory(); $toml = $factory->fromString(' [server] host = "localhost" port = 8080 enabled = true '); $toml->get('server.host'); // "localhost" $toml->get('server.port'); // 8080 $toml->get('server.enabled'); // true $toml->toArray(); // ['server' => ['host' => 'localhost', 'port' => 8080, 'enabled' => true]]
Encoding to TOML
use HypnoTox\Toml\Toml; $toml = Toml::fromArray([ 'title' => 'My App', 'database' => [ 'host' => '127.0.0.1', 'port' => 5432, 'enabled' => true, ], ]); echo $toml->toString(); // title = "My App" // // [database] // host = "127.0.0.1" // port = 5432 // enabled = true
Working with Toml objects
// Immutable set (returns a new instance) $updated = $toml->set('server.host', '0.0.0.0'); // Get as PHP array $array = $toml->toArray(); // Encode back to TOML string $string = $toml->toString();
Features
- Full TOML v1.0.0 specification support
- Tables, inline tables, array of tables
- All key types (bare, quoted, dotted)
- All data types: string (basic, literal, multiline), integer (decimal, hex, octal, binary), float (including inf/nan), boolean, offset date-time, local date-time, local date, local time, array
- Bidirectional: decode TOML to PHP arrays and encode PHP arrays to TOML
- Immutable
Tomldata objects - Strict validation with detailed error messages including line/column numbers