hypnotox/toml

A PHP package implementing a TOML file loader.

Maintainers

Package info

github.com/hypnotox/php-toml

pkg:composer/hypnotox/toml

Statistics

Installs: 43

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.1 2026-03-28 13:13 UTC

This package is auto-updated.

Last update: 2026-03-28 14:03:09 UTC


README

CI Status Code Coverage Packagist Version Packagist PHP Version Support GitHub

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 Toml data objects
  • Strict validation with detailed error messages including line/column numbers

License

MIT