PHPackages                             app-hive/toml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. app-hive/toml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

app-hive/toml
=============

A fast, lightweight TOML parser for PHP with TOML 1.1.0 support.

0.0.2(4mo ago)122MITPHPPHP ^8.3

Since Feb 3Pushed 4mo agoCompare

[ Source](https://github.com/app-hive/toml)[ Packagist](https://packagist.org/packages/app-hive/toml)[ RSS](/packages/app-hive-toml/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

AppHive TOML
============

[](#apphive-toml)

A fast, lightweight TOML parser for PHP with TOML 1.1.0 support.

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Installation
------------

[](#installation)

Install via Composer:

```
composer require app-hive/toml
```

Basic Usage
-----------

[](#basic-usage)

### Parsing a TOML String

[](#parsing-a-toml-string)

```
use AppHive\Toml\Toml;

$toml = parse();
$warnings = $parser->getWarnings();

foreach ($warnings as $warning) {
    echo $warning->getMessage();
    echo $warning->getErrorLine();
    echo $warning->getErrorColumn();
}
```

For files:

```
$parser = Toml::createParserForFile('/path/to/config.toml', ParserConfig::lenient());
$result = $parser->parse();
$warnings = $parser->getWarnings();
```

**Note:** Syntax errors (malformed tokens, unexpected characters) always throw exceptions regardless of mode. Only semantic violations (like duplicate keys or table redefinitions) can be collected as warnings.

Exception Handling
------------------

[](#exception-handling)

The parser throws `TomlParseException` for invalid TOML input. The exception provides detailed error information including line and column numbers:

```
use AppHive\Toml\Toml;
use AppHive\Toml\Exceptions\TomlParseException;

try {
    $config = Toml::parse($invalidToml);
} catch (TomlParseException $e) {
    echo $e->getMessage();     // Error message with location
    echo $e->getErrorLine();   // Line number where error occurred
    echo $e->getErrorColumn(); // Column number where error occurred
    echo $e->getSnippet();     // Code snippet showing error location
}
```

### Common Errors

[](#common-errors)

```
// Duplicate key
Toml::parse('key = 1' . "\n" . 'key = 2');
// TomlParseException: Cannot redefine key 'key' at line 2, column 1

// Invalid escape sequence
Toml::parse('str = "hello\q"');
// TomlParseException: Invalid escape sequence: \q

// Unterminated string
Toml::parse('str = "hello');
// TomlParseException: Unterminated basic string

// File not found
Toml::parseFile('/nonexistent/file.toml');
// TomlParseException: File does not exist: /nonexistent/file.toml
```

TOML 1.1.0 Features
-------------------

[](#toml-110-features)

This library supports TOML 1.1.0 features including:

### Escape Sequences

[](#escape-sequences)

- `\e` - Escape character (U+001B)
- `\xNN` - Hexadecimal escape (2 hex digits)

```
escape = "Hello\e[31mRed\e[0m"
hex = "\x1B[31mRed\x1B[0m"
```

### Trailing Commas

[](#trailing-commas)

Arrays and inline tables support trailing commas:

```
colors = [
    "red",
    "green",
    "blue",
]

point = {
    x = 1,
    y = 2,
}
```

### Newlines in Inline Tables

[](#newlines-in-inline-tables)

Inline tables can span multiple lines:

```
config = {
    name = "app",
    version = "1.0.0",
    debug = true,
}
```

API Reference
-------------

[](#api-reference)

### `Toml::parse(string $toml): array`

[](#tomlparsestring-toml-array)

Parse a TOML string and return an associative array.

**Parameters:**

- `$toml` - The TOML string to parse

**Returns:** An associative array representing the parsed TOML

**Throws:** `TomlParseException` if the input is invalid TOML

### `Toml::parseFile(string $path): array`

[](#tomlparsefilestring-path-array)

Parse a TOML file and return an associative array.

**Parameters:**

- `$path` - Path to the TOML file

**Returns:** An associative array representing the parsed TOML

**Throws:** `TomlParseException` if the file doesn't exist, isn't readable, or contains invalid TOML

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

This runs PHPStan static analysis followed by Pest tests, including the official TOML test suite.

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

141d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6216c36a8a2b7b6afbd86366a19b8175542b37cdf305ea54c8c4cf71c9840fb5?d=identicon)[PhiloNL](/maintainers/PhiloNL)

---

Top Contributors

[![PhiloNL](https://avatars.githubusercontent.com/u/1133950?v=4)](https://github.com/PhiloNL "PhiloNL (54 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/app-hive-toml/health.svg)

```
[![Health](https://phpackages.com/badges/app-hive-toml/health.svg)](https://phpackages.com/packages/app-hive-toml)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
